summaryrefslogtreecommitdiffstats
path: root/lib/msun/src/s_rint.c
Commit message (Collapse)AuthorAgeFilesLines
* s/rcsid/__FBSDID/das2008-02-221-3/+2
|
* Use STRICT_ASSIGN() instead of assorted direct volatile hacks to workbde2008-01-191-2/+2
| | | | | | | | | | | | | | | | | | around assignments not working for gcc on i386. Now volatile hacks for rint() and rintf() don't needlessly pessimize so many arches and the remaining pessimizations (for arm and powerpc) can be avoided centrally. This cleans up after s_rint.c 1.3 and 1.13 and s_rintf.c 1.3 and 1.9: - s_rint.c 1.13 broke 1.3 by only using a volatile cast hack in 1 place when it was needed in 2 places, and the volatile cast hack stopped working with gcc-4. These bugs only affected correctness tests on i386 since i386 normally uses asm rint() and doesn't support the extra precision mode that would break assignments of doubles. - s_rintf.c 1.9 improved(?) on 1.3 by using a volatile variable hack instead of an extra-precision variable hack, but it declared 2 variables as volatile when only 1 variable needed to be volatile. This only affected speed tests on i386 since i386 uses asm rintf().
* Implement rintl(), nearbyintl(), lrintl(), and llrintl().das2008-01-141-0/+6
| | | | Thanks to bde@ for feedback and testing of rintl().
* Simplified the fix in rev.1.3. Instead of using long double forbde2005-12-031-8/+2
| | | | | | | | | | TWO52[sx] to trick gcc into correctly converting TWO52[sx]+x to double on assignment to "double w", force a correct assignment by assigning to *(double *)&w. This is cleaner and avoids the double rounding problem on machines that evaluate double expressions in double precision. It is not necessary to convert w-TWO52[sx] to double precision on return as implied in the comment in rev.1.3, since the difference is exact.
* Fixed rint(x) in the following cases:bde2005-12-031-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (1) In round-to-nearest mode, on all machines, fdlibm rint() never worked for |x| = n+0.75 where n is an even integer between 262144 and 524286 inclusive (2*131072 cases). To avoid double rounding on some machines, we begin by adjusting x to a value with the 0.25 bit not set, essentially by moving the 0.25 bit to a lower bit where it works well enough as a guard, but we botched the adjustment when log2(|x|) == 18 (2*2**52 cases) and ended up just clearing the 0.25 bit then. Most subcases still worked accidentally since another lower bit serves as a guard. The case of odd n worked accidentally because the rounding goes the right way then. However, for even n, after mangling n+0.75 to 0.5, rounding gives n but the correct result is n+1. (2) In round-towards-minus-infinity mode, on all machines, fdlibm rint() never for x = n+0.25 where n is any integer between -524287 and -262144 inclusive (262144 cases). In these cases, after mangling n+0.25 to n, rounding gives n but the correct result is n-1. (3) In round-towards-plus-infinity mode, on all machines, fdlibm rint() never for x = n+0.25 where n is any integer between 262144 and 524287 inclusive (262144 cases). In these cases, after mangling n+0.25 to n, rounding gives n but the correct result is n+1. A variant of this bug was fixed for the float case in rev.1.9 of s_rintf.c, but the analysis there is incomplete (it only mentions (1)) and the fix is buggy. Example of the problem with double rounding: rint(1.375) on a machine which evaluates double expressions with just 1 bit of extra precision and is in round-to-nearest mode. We evaluate the result using (double)(2**52 + 1.375) - 2**52. Evaluating 2**52 + 1.375 in (53+1) bit prcision gives 2**52 + 1.5 (first rounding). (Second) rounding of this to double gives 2**52 + 2.0. Subtracting 2**52 from this gives 2.0 but we want 1.0. Evaluating 2**52 + 1.375 in double precision would have given the desired intermediate result of 2**52 + 1.0. The double rounding problem is relatively rare, so the botched adjustment can be fixed for most machines by removing the entire adjustment. This would be a wrong fix (using it is 1 of the bugs in rev.1.9 of s_rintf.c) since fdlibm is supposed to be generic, but it works in the following cases: - on all machines that evaluate double expressions in double precision, provided either long double has the same precision as double (alpha, and i386's with precision forced to double) or my earlier fix to use a long double 2**52 is modified to avoid using long double precision. - on all machines that evaluate double expressions in many more than 11 bits of extra precision. The 1 bit of extra precision in the example is the worst case. With N bits of extra precision, it sufices to adjust the bit N bits below the 0.5 bit. For N >= about 52 there is no such bit so the adjustment is both impossible and unnecessary. The fix in rev.1.9 of s_rintf.c apparently depends on corresponding magic in float precision: on all supported machines N is either 0 or >= 24, so double rounding doesn't occur in practice. - on all machines that don't use fdlibm rint*() (i386's). So under FreeBSD, the double rounding problem only affects amd64 now, but should only affect i386 in future (when double expressions are evaluated in long double precision).
* Remove an obsolete sentence from a comment.stefanf2005-03-071-2/+1
|
* Only provide one copy of the math functions. If we provide a MD function,peter2003-07-231-1/+1
| | | | | | | | do not also provide a __generic_XXX version as well. This is how we used to runtime select the generic vs i387 versions on the i386 platform. This saves a pile of #defines in the src/math_private.h file to undo the __generic_XXX renames in some of the *.c files.
* Fix formatting, this is hard to explain, so I'll show one example.alfred2002-05-281-1/+2
| | | | | | | | | | - float ynf(int n, float x) /* wrapper ynf */ +float +ynf(int n, float x) /* wrapper ynf */ This is because the __STDC__ stuff was indented. Reviewed by: md5
* Assume __STDC__, remove non-__STDC__ code.alfred2002-05-281-9/+0
| | | | Reviewed by: md5
* $Id$ -> $FreeBSD$peter1999-08-281-1/+1
|
* Revert $FreeBSD$ to $Id$peter1997-02-221-1/+1
|
* Select between the generic math functions and the i387-specific onesbde1997-02-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | at runtime. etc/make.conf: Nuked HAVE_FPU option. lib/msun/Makefile: Always build the i387 objects. Copy the i387 source files at build time so that the i387 objects have different names. This is simpler than renaming the files in the cvs repository or repeating half of bsd.lib.mk to add explicit rules. lib/msun/src/*.c: Renamed all functions that have an i387-specific version by adding `__generic_' to their names. lib/msun/src/get_hw_float.c: New file for getting machdep.hw_float from the kernel. sys/i386/include/asmacros.h: Abuse the ENTRY() macro to generate jump vectors and associated code. This works much like PIC PLT dynamic initialization. The PIC case is messy. The old i387 entry points are renamed. Renaming is easier here because the names are given by macro expansions.
* Make the long-awaited change from $Id$ to $FreeBSD$jkh1997-01-141-1/+1
| | | | | | | | This will make a number of things easier in the future, as well as (finally!) avoiding the Id-smashing problem which has plagued developers for so long. Boy, I'm glad we're not using sup anymore. This update would have been insane otherwise.
* Made rintf() actually work. It was completely broken (when s_rint.cbde1996-08-281-3/+10
| | | | | | | | | | | was compiled with -O) by the precision bug in the i386 version of gcc (assignments and casts don't clip the precision). E.g., rintf(12.3456789) was 12.125. Avoid the same bug in rint(). It was only broken for the unusual case when the i387 precision is 64 bits. FreeBSD defaults to 53 bit precision to avoid problems like this, but the standard math emulator always uses 64 bit precision.
* Remove trailing whitespace.rgrimes1995-05-301-4/+4
|
* J.T. Conklin's latest version of the Sun math library.jkh1994-08-191-0/+86
-- Begin comments from J.T. Conklin: The most significant improvement is the addition of "float" versions of the math functions that take float arguments, return floats, and do all operations in floating point. This doesn't help (performance) much on the i386, but they are still nice to have. The float versions were orginally done by Cygnus' Ian Taylor when fdlibm was integrated into the libm we support for embedded systems. I gave Ian a copy of my libm as a starting point since I had already fixed a lot of bugs & problems in Sun's original code. After he was done, I cleaned it up a bit and integrated the changes back into my libm. -- End comments Reviewed by: jkh Submitted by: jtc
OpenPOWER on IntegriCloud