Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

classify_float #8417

Closed
vicuna opened this issue Dec 16, 2003 · 4 comments
Closed

classify_float #8417

vicuna opened this issue Dec 16, 2003 · 4 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Dec 16, 2003

Original bug ID: 1982
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Shawn Wagner
Version: 3.07+2
OS: linux
Submission from: dialup-67.75.211.174.dial1.seattle.level3.net (67.75.211.174)

classify_float appears to be broken, always returning FP_subnormal no matter the
number it's called on. Witness:

[shawnw@sherlock shawnw]$ ocaml
Objective Caml version 3.07+2

classify_float 0.0;;

  • : fpclass = FP_subnormal

classify_float 1.0;;

  • : fpclass = FP_subnormal

classify_float infinity;;

  • : fpclass = FP_subnormal

classify_float nan;;

  • : fpclass = FP_subnormal

classify_float 1e25;;

  • : fpclass = FP_subnormal

@vicuna
Copy link
Author

vicuna commented Dec 20, 2003

Comment author: administrator

On Sat, Dec 20, 2003 at 12:43:25PM +0100, Xavier Leroy wrote:

Version: 3.07+2
OS: linux
classify_float appears to be broken, always returning FP_subnormal
no matter the number it's called on.

Works fine here (Linux RH 9 / x86). Normally, classify_float is a thin
wrapper around the ISO C macro fpclassify(). If that macro is not
available, emulation code is invoked.

Could you please provide more details on your environment (especially
if it's a non-x86 platform), and perhaps run byterun/floats.c through
cpp to see what code for classify_float was selected.

x86, glibc 2.2.5, gcc 3.3.2. I've discovered that while the C library does
have fpclassify(), it's included in math.h only in C99 mode (gcc
-std=gnu99), and not by default, so when I compiled ocaml, the emulation
code is being used.

--
Shawn Wagner
shawnw@speakeasy.org

@vicuna
Copy link
Author

vicuna commented Dec 20, 2003

Comment author: administrator

Version: 3.07+2
OS: linux
classify_float appears to be broken, always returning FP_subnormal
no matter the number it's called on.

Works fine here (Linux RH 9 / x86). Normally, classify_float is a thin
wrapper around the ISO C macro fpclassify(). If that macro is not
available, emulation code is invoked.

Could you please provide more details on your environment (especially
if it's a non-x86 platform), and perhaps run byterun/floats.c through
cpp to see what code for classify_float was selected.

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Dec 20, 2003

Comment author: administrator

On Sat, Dec 20, 2003 at 12:43:25PM +0100, Xavier Leroy wrote:

Version: 3.07+2
OS: linux
classify_float appears to be broken, always returning FP_subnormal
no matter the number it's called on.

Works fine here (Linux RH 9 / x86). Normally, classify_float is a thin
wrapper around the ISO C macro fpclassify(). If that macro is not
available, emulation code is invoked.

Could you please provide more details on your environment (especially
if it's a non-x86 platform), and perhaps run byterun/floats.c through
cpp to see what code for classify_float was selected.

I've had a chance to do some more testing, and discovered that the casts in
the fpclassify emulation code are breaking gcc's strict-aliasing rules.
Compiling with -fno-strict-aliasing gives results that come out right. So
does using something like the following:

union {
double d;
struct {
#ifdef ARCH_BIG_ENDIAN
uint32 h;
uint32 l;
#else
uint32 l;
uint32 h;
#endif
} i;
} val;
val.d = Double_val(d);
val.i.l = val.i.l | (val.i.h & 0xFFFFF);
val.i.h = val.i.h & 0x7FF00000;
if ((val.i.h | val.i.l) == 0)
return Val_int(FP_zero);
if (val.i.h == 0)
return Val_int(FP_subnormal);
if (val.i.h == 0x7FF00000) {
if (val.i.l == 0)
return Val_int(FP_infinite);
else
return Val_int(FP_nan);
}
return Val_int(FP_normal);
}

--
Shawn Wagner
shawnw@speakeasy.org

@vicuna
Copy link
Author

vicuna commented Jan 9, 2004

Comment author: administrator

Fixed as suggested 2004-01-09 by XL.

@vicuna vicuna closed this as completed Jan 9, 2004
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant