diff options
Diffstat (limited to 'nuttx/libc/math/lib_sinh.c')
-rw-r--r-- | nuttx/libc/math/lib_sinh.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/nuttx/libc/math/lib_sinh.c b/nuttx/libc/math/lib_sinh.c index da79e7cfd..714a52816 100644 --- a/nuttx/libc/math/lib_sinh.c +++ b/nuttx/libc/math/lib_sinh.c @@ -3,7 +3,7 @@ * * This file is a part of NuttX: * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. * Ported by: Darcy Gong * * It derives from the Rhombs OS math library by Nick Johnson which has @@ -41,7 +41,22 @@ #ifdef CONFIG_HAVE_DOUBLE double sinh(double x) { - x = exp(x); - return ((x - (1.0 / x)) / 2.0); + double y; + double z; + + if (fabs(x) < 1E-5) + { + /* x + 1/3! * x^3 + 1/5! * x^5 + 1/7! * x^7 + ... */ + + z = x * x; + y = x * (1.0 + z / 6.0); + } + else + { + z = exp(x); + y = (z - 1.0 / z) / 2.0; + } + + return y; } #endif |