aboutsummaryrefslogtreecommitdiff
path: root/newlib/libm
AgeCommit message (Collapse)AuthorFilesLines
2020-03-19Fix hypotf missing mask in hi+lo decompositionFabian Schriever1-2/+2
Add the missing mask for the decomposition of hi+lo which caused some errors of 1-2 ULP. This change is taken over from FreeBSD: https://github.com/freebsd/freebsd/commit/95436ce20dab5a34ba46373410b96411b1734578 Additionally I've removed some variable assignments which were never read before being overwritten again in the next 2 lines.
2020-03-19Fix modf/f for NaN inputFabian Schriever2-0/+2
For NaN input the modf/f procedures should return NaN instead of zero with the sign of the input.
2020-03-18Fix for k_tan.c specific inputsFabian Schriever1-8/+21
This fix for k_tan.c is a copy from fdlibm version 5.3 (see also http://www.netlib.org/fdlibm/readme), adjusted to use the macros available in newlib (SET_LOW_WORD). This fix reduces the ULP error of the value shown in the fdlibm readme (tan(1.7765241907548024E+269)) to 0.45 (thereby reducing the error by 1). This issue only happens for large numbers that get reduced by the range reduction to a value smaller in magnitude than 2^-28, that is also reduced an uneven number of times. This seems rather unlikely given that one ULP is (much) larger than 2^-28 for the values that may cause an issue. Although given the sheer number of values a double can represent, it is still possible that there are more affected values, finding them however will be quite hard, if not impossible. We also took a look at how another library (libm in FreeBSD) handles the issue: In FreeBSD the complete if branch which checks for values smaller than 2^-28 (or rather 2^-27, another change done by FreeBSD) is moved out of the kernel function and into the external function. This means that the value that gets checked for this condition is the unreduced value. Therefore the input value which caused a problem in the fdlibm/newlib kernel tan will run through the full polynomial, including the careful calculation of -1/(x+r). So the difference is really whether r or y is used. r = y + p with p being the result of the polynomial with 1/3*x^3 being the largest (and magnitude defining) value. With x being <2^-27 we therefore know that p is smaller than y (y has to be at least the size of the value of x last mantissa bit divided by 2, which is at least x*2^-51 for doubles) by enough to warrant saying that r ~ y. So we can conclude that the general implementation of this special case is the same, FreeBSD simply has a different philosophy on when to handle especially small numbers.
2020-03-11Fix truncf for sNaN inputFabian Schriever1-1/+1
Make line 47 in sf_trunc.c reachable. While converting the double precision function trunc to the single precision version truncf an error was introduced into the special case. This special case is meant to catch both NaNs and infinities, however qNaNs and infinities work just fine with the simple return of x (line 51). The only error occurs for sNaNs where the same sNaN is returned and no invalid exception is raised.
2020-03-10i386/fenv.c: Include fenv.c implementation shared with x86_64, not stubJoel Sherrill1-1/+1
2020-03-10Fix error in fdim/f for infinitiesFabian Schriever2-8/+2
The comparison c == FP_INFINITE causes the function to return +inf as it expects x = +inf to always be larger than y. This shortcut causes several issues as it also returns +inf for the following cases: - fdim(+inf, +inf), expected (as per C99): +0.0 - fdim(-inf, any non NaN), expected: +0.0 I don't see a reason to keep the comparison as all the infinity cases return the correct result using just the ternary operation.
2020-03-09Fix error in exp in magnitude [2e-32,2e-28]Fabian Schriever2-2/+2
While testing the exp function we noticed some errors at the specified magnitude. Within this range the exp function returns the input value +1 as an output. We chose to run a test of 1m exponentially spaced values in the ranges [-2^-27,-2^-32] and [2^-32,2^-27] which showed 7603 and 3912 results with an error of >=0.5 ULP (compared with MPFR in 128 bit) with the highest being 0.56 ULP and 0.53 ULP. It's easy to fix by changing the magnitude at which the input value +1 is returned from <2^-28 to <2^-32 and using the polynomial instead. This reduces the number of results with an error of >=0.5 ULP to 485 and 479 in above tests, all of which are exactly 0.5 ULP. As we were already checking on exp we also took a look at expf. For expf the magnitude where the input value +1 is returned can be increased from <2^-28 to <2^-23 without accuracy loss for a slight performance improvement. To ensure this was the correct value we tested all values in the ranges [-2^-17,-2^-28] and [2^-28,2^-17] (~92.3m values each).
2020-03-03Fix error in float trig. function range reductionFabian Schriever1-1/+1
The single-precision trigonometric functions show rather high errors in specific ranges starting at about 30000 radians. For example the sinf procedure produces an error of 7626.55 ULP with the input 5.195880078125e+04 (0x474AF6CD) (compared with MPFR in 128bit precision). For the test we used 100k values evenly spaced in the range of [30k, 70k]. The issues are periodic at higher ranges. This error was introduced when the double precision range reduction was first converted to float. The shift by 8 bits always returns 0 as iq is never higher than 255. The fix reduces the error of the example above to 0.45 ULP, highest error within the test set fell to 1.31 ULP, which is not perfect, but still a significant improvement. Testing other previously erroneous ranges no longer show particularly large accuracy errors.
2020-03-02Fix error in powf for (-1.0, NaN) inputFabian Schriever1-1/+1
Prevent confusion between -1.0 and 1.0 in powf. The corresponding similar error was previously fixed for pow (see commit bb25dd1b)
2020-02-25x86_64/i386 fenv: Replace symlink with include fenv_stub.cJoel Sherrill23-23/+161
Having symlinks for these files led to an issue reported to the RTEMS Project that showed up using some tar for native Windows to unpack the newlib sources. It creates symlinks in the tar file as copies of the files the symlinks point to. If the links appear in the tar file before the source exists, it cannot copy the file. The solution in this patch is to convert the files that are symbolic links into simple files which include the file they were linked to. This should be more portable and avoids the symbolinc link problem.
2020-02-14pow: fix pow(-1.0, NaN)Nicolas Brunie1-1/+1
I think I may have encountered a bug in the implementation of pow: pow(-1.0, NaN) returns 1.0 when it should return NaN. Because ix is used to check input vs 1.0 rather than hx, -1.0 is mistaken for 1.0
2020-02-06Typo in license terms for newlib/libm/common/log2.cKeith Packard1-1/+1
The closing quotes were in the wrong place Signed-off-by: Keith Packard <keithp@keithp.com>
2020-01-21Bump up newlib release to 3.3.0Jeff Johnston10-100/+100
2020-01-02Bump up release to 3.2.0 for yearly snapshotnewlib-snapshot-20200102newlib-3.2.0Jeff Johnston10-100/+100
2019-12-02libm: switch sf_log1p from double error routines to floatKeith Packard2-4/+2
sf_log1p was using __math_divzero and __math_invalid, which drag in a pile of double-precision code. Switch to using the single-precision variants. This also required making those available in __OBSOLETE_MATH mode. Signed-off-by: Keith Packard <keithp@keithp.com>
2019-10-31PRU: Align libmath to PRU ABIDimitar Dimitrov17-2/+6718
The TI proprietary toolchain uses nonstandard names for some math library functions. In order to achieve ABI compatibility between GNU and TI toolchains, add support for the TI function names. Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
2019-10-31Fix some generated filesJeff Johnston4-16/+16
2019-10-08Add patch from Joel Sherrill for i386 and x86_64 fenv supportJeff Johnston34-9/+16372
2019-09-03fe_dfl_env.c: Fix typo in commentJoel Sherrill1-1/+1
2019-08-15fenv: Include documentation in generated .info fileJoel Sherrill5-2/+49
2019-08-13fenv: Fix typo-ed variable name in documentationJon Turney1-1/+1
2019-08-13fenv: Fix mangled makedoc markupJon Turney4-8/+8
See makedoc.c:657: Variables are marked up as '<[foo]>'. Code is marked up as '<<foo>>'.
2019-08-13fenv: fe_dfl_env.c doesn't contain any documentationJon Turney2-2/+2
fe_dfl_env.c doesn't contain any documentation, so drop it from makedoc processing.
2019-08-09Regenerated files from fenv.h additionJoel Sherrill3-7/+636
2019-08-09Add default implementation of fenv.h and all methodsJoel Sherrill15-5/+842
The default implementation of the fenv.h methods return -EOPNOTSUP. Some of these have implementations appropriate for soft-float. The intention of the new fenv.h is that it be portable and that architectures provide their own implementation of sys/fenv.h.
2019-08-09Miscellaneous Makefile.in regeneratedJoel Sherrill1-3/+4
2019-07-26common/math_errf.c: Enable compilation of __math_oflowfJoel Sherrill1-2/+3
This resolved linking errors when using methods such as expm1().
2019-07-09Set errno in expm1{,f} / log1p{,f}Jeff Johnston4-6/+14
2019-07-09 Joern Rennecke <joern.rennecke@riscy-ip.com> * libm/common/s_expm1.c ("math_config.h"): Include. (expm1): Use __math_oflow to set errno. * libm/common/s_log1p.c ("math_config.h"): Include. (log1p): Use __math_divzero and __math_invalid to set errno. * libm/common/sf_expm1.c ("math_config.h"): Include. (expm1f): Use __math_oflow to set errno. * libm/common/sf_log1p.c ("math_config.h"): Include. (log1pf): Use __math_divzero and __math_invalid to set errno.
2019-01-23Use nanf() instead of nan() in single-precision float libm math functionsJozef Lawrynowicz4-4/+4
This patch reduces code size for a few single-precision float math functions, by using nanf() instead of nan() where required.
2019-01-23Use HUGE_VALF instead of HUGE_VAL in single-precision float libm math functionsJozef Lawrynowicz16-18/+18
This patch replaces instances of "(float).*HUGE_VAL" with a direct usage of HUGE_VALF, which is also defined in math.h.
2019-01-23Remove HUGE_VAL definition from libm math functionsJozef Lawrynowicz31-186/+0
This patch removes the definitions of HUGE_VAL from some of the float math functions. HUGE_VAL is defined in newlib/libc/include/math.h, so it is not necessary to have a further definition in the math functions.
2019-01-23Remove matherr, and SVID and X/Open math library configurationsJozef Lawrynowicz72-2257/+404
Default math library configuration is now IEEE
2018-12-31Bump release to 3.1.0 for yearly snapshotnewlib-snapshot-20181231newlib-3.1.0Jeff Johnston8-82/+96
2018-12-10Fix powf overflow handling in non-nearest rounding modeSzabolcs Nagy1-0/+10
The threshold value at which powf overflows depends on the rounding mode and the current check did not take this into account. So when the result was rounded away from zero it could become infinity without setting errno to ERANGE. Example: pow(0x1.7ac7cp+5, 23) is 0x1.fffffep+127 + 0.1633ulp If the result goes above 0x1.fffffep+127 + 0.5ulp then errno is set, which is fine in nearest rounding mode, but powf(0x1.7ac7cp+5, 23) is inf in upward rounding mode powf(-0x1.7ac7cp+5, 23) is -inf in downward rounding mode and the previous implementation did not set errno in these cases. The fix tries to avoid affecting the common code path or calling a function that may introduce a stack frame, so float arithmetics is used to check the rounding mode and the threshold is selected accordingly.
2018-10-10Implement nanl in newlib onlyCorinna Vinschen1-0/+6
Drop Cygwin-specific nanl in favor of a generic implementation in newlib. Requires GCC 3.3 or later. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-09-28Update Arm copyright notices in new math filesWilco Dijkstra26-47/+79
While working on the strstr patch I noticed several copyright headers of the new math functions are missing closing quotes after ``AS IS. I've added these. Also update spellings of Arm Ltd in a few places (but still use ARM LTD in upper case portion). Finally add SPDX identifiers to make everything consistent.
2018-09-18Fix the documentation comment of checkintSzabolcs Nagy2-2/+4
checkint in pow is not supposed to be used with 0, inf or nan inputs.
2018-09-06Document the log table generation methodSzabolcs Nagy3-0/+74
Add comments with enough detail so the log lookup tables can be recreated.
2018-09-03math_config.h: Fix signed overflow warning for 16-bit targetscygwin-2_11_1-releaseJon Beniston1-1/+1
2018-09-03e_scalb.c: Call scalbln instead of scalbn on 16-bit targets to ensure ↵Jon Beniston1-0/+5
constant fits in an int.
2018-08-31Add --disable-newlib-fno-builtin to allow compilation without -fno-builtin ↵newlib-snapshot-20180831Jon Beniston8-22/+104
for smaller and faster code.
2018-08-29Remove unused variable 'one' from sf_cos.cKeith Packard1-6/+0
Defined, never mentioned. Signed-off-by: Keith Packard <keithp@keithp.com>
2018-08-16Improve sincosf commentsWilco Dijkstra4-21/+26
Improve comments in sincosf implementation to make the code easier to understand. Rename the constant pi64 to pi63 since it's actually PI * 2^-63. Add comments for fields of sincos_t structure. Add comments describing implementation details to reduce_fast.
2018-08-08newlib: don't use __visibility__ attrribute on CygwinCorinna Vinschen1-2/+7
gcc doesn't support visibility attribute on PE/COFF platforms Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-08-08newlib: fix various gcc warningsCorinna Vinschen5-4/+7
* unused variables * potentially used uninitialized * suggested bracketing * misleading indentation Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-07-11Remove float compare option from sincosfSzabolcs Nagy1-10/+1
PREFER_FLOAT_COMPARISON setting was not correct as it could raise spurious exceptions. Fixing it is easy: just use ISLESS(x, y) instead of abstop12(x) < abstop12(y) with appropriate non-signaling definition for ISLESS. However it seems this setting is not very useful (there is only minor performance difference on various architectures), so remove this option for now.
2018-07-11Fix the documentation comments for log_inline in powSzabolcs Nagy1-3/+3
There was a typo and the arguments were not explained clearly.
2018-07-06Fix namespace issues in sinf, cosf and sincosfSzabolcs Nagy5-18/+19
Use const sincos_t for clarity instead of making the typedef const. Use __inv_pi4 and __sincosf_table to avoid namespace issues with static linking.
2018-07-06Fix large ulp error in pow without fma very near 1.0Szabolcs Nagy1-2/+4
The !HAVE_FAST_FMA code path split r = z/c - 1 into r = rhi + rlo such that when z = 1-tiny and c = 1 then rlo and rhi could have much larger magnitude than r which later caused large rounding errors. So do a nearest rounding instead of truncation at the split. In newlib with default settings this was observable on some arm targets that enable the new math code but has no fma.
2018-07-06Change the return type of converttoint and document the semanticsSzabolcs Nagy1-1/+9
The roundtoint and converttoint internal functions are only called with small values, so 32 bit result is enough for converttoint and it is a signed int conversion so the natural return type is int32_t. The original idea was to help the compiler keeping the result in uint64_t, then it's clear that no sign extension is needed and there is no accidental undefined or implementation defined signed int arithmetics. But it turns out gcc does a good job with inlining so changing the type has no overhead and the semantics of the conversion is less surprising this way. Since we want to allow the asuint64 (x + 0x1.8p52) style conversion, the top bits were never usable and the existing code ensures that only the bottom 32 bits of the conversion result are used. In newlib with default settings only aarch64 is affected and there is no significant code generation change with gcc after the patch.