Date: Tue, 2 Mar 1999 12:03:04 -0500 (EST) From: "Crist J. Clark" <cjc@cc942873-a.ewndsr1.nj.home.com> To: freebsd-questions@FreeBSD.ORG (FreeBSD Questions) Subject: FP Math Message-ID: <199903021703.MAA02135@cc942873-a.ewndsr1.nj.home.com>
next in thread | raw e-mail | index | archive | help
I have been having some trouble with floating point operations, namely the dreaded, Floating exception (core dumped) Having a look at 'man math' only really served to confuse me more. The manpage lays out information about two libraries, DEC VAX-11 D_floating-point and IEEE STANDARD 754 Floating-Point Arithmetic. However, no where does the manpage really come clean and admit what we are using. I _think_ I am using the IEEE Standard, but have been getting weird results. See below for an example. I think the problems are related to float-double issues. Why does the manpage inform me about both? Does it mean I can somehow select one or the other? If I can, how do I do it? Thanks. Example: Here are two quick C program that I think show why I am confused. The first produces an exception and core dumps (for me anyway). In this one, I have set floats to values outside of their range. It dumps at the point marked, --- C Code --- #include <stdio.h> int main() { float a = -1.0e-41; float b = -1.0e-41; float c = 1.0e-41; float d; printf("%g\n%g\n",a,c); /* This outputs values a and b different than those set */ d = a/b; /* This works */ printf("%g\n",d); /* Still OK */ d /= c; /* FP exception, core dump */ printf("%g\n",d); return 0; } --- End C Code --- Now the problem printing I could understand. I have set the floats outside of their range. However, if I change the initial values slightly, --- C Code --- #include <stdio.h> int main() { float a = -1.0e41; float b = -1.0e-41; float c = 1.0e-41; float d; printf("%g\n%g\n",a,c); /* This gets a as it should be now */ d = a/b; /* This works */ printf("%g\n",d); /* Still OK */ d /= c; /* now this works! */ printf("%g\n",d); return 0; } --- End C Code --- Could someone explain this? [Should I send this to -hackers instead?] -- Crist J. Clark cjclark@home.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903021703.MAA02135>