> Here's a diff that sticks a bit closer to the original code. It's
> equivalent to your diff, and admittedly purely a matter of taste which
> version to prefer.
I prefer my version better. It's not '93 anymore and compilers are
able to convert 0.0L and -1.0L precisely, otherwise we have a huge
problem. There's no need to obfuscate here by manually converting
to floating point representation.
Here's a diff which also includes same fix for ld128. OK?
Index: ld128/s_floorl.c
===================================================================
RCS file: /cvs/src/lib/libm/src/ld128/s_floorl.c,v
retrieving revision 1.1
diff -u -r1.1 s_floorl.c
--- ld128/s_floorl.c 6 Jul 2011 00:02:42 -0000 1.1
+++ ld128/s_floorl.c 11 Feb 2014 05:24:15 -0000
@@ -34,10 +34,11 @@
jj0 = ((i0>>48)&0x7fff)-0x3fff;
if(jj0<48) {
if(jj0<0) { /* raise inexact if x != 0 */
- if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
- if(i0>=0) {i0=i1=0;}
+ if(huge+x>0.0) {
+ if(i0>=0)
+ return 0.0L;
else if(((i0&0x7fffffffffffffffLL)|i1)!=0)
- { i0=0xbfff000000000000ULL;i1=0;}
+ return -1.0L;
}
} else {
i = (0x0000ffffffffffffULL)>>jj0;
Index: ld80/s_floorl.c
===================================================================
RCS file: /cvs/src/lib/libm/src/ld80/s_floorl.c,v
retrieving revision 1.2
diff -u -r1.2 s_floorl.c
--- ld80/s_floorl.c 25 Jul 2011 16:20:09 -0000 1.2
+++ ld80/s_floorl.c 11 Feb 2014 05:24:01 -0000
@@ -35,10 +35,11 @@
jj0 = (se&0x7fff)-0x3fff;
if(jj0<31) {
if(jj0<0) { /* raise inexact if x != 0 */
- if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
- if(sx==0) {se=0;i0=i1=0;}
+ if(huge+x>0.0) {
+ if(sx==0)
+ return 0.0L;
else if(((se&0x7fff)|i0|i1)!=0)
- { se=0xbfff;i0=i1=0;}
+ return -1.0L;
}
} else {
i = (0x7fffffff)>>jj0;