Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

BrowserUk's scratchpad

by BrowserUk (Pope)
on Jun 01, 2004 at 22:28 UTC ( #358718=scratchpad: print w/replies, xml ) Need Help??

#include <stdio.h> #include <float.h> typedef unsigned __int64 U64; typedef struct { U64 b; const char *desc; } FPCONST; FPCONST pats[] = { { 0x0000000000000000, "+zero " }, { 0x0000000000000001, "+denorm lo" }, { 0x000fffffffffffff, "+denorm hi" }, { 0x0010000000000000, "+norm lo" }, { 0x7fefffffffffffff, "+norm hi" }, { 0x7ff0000000000000, "+infinity " }, { 0x7ff0000000000001, "+sNaN lo" }, { 0x7ff7ffffffffffff, "+sNaN hi" }, { 0x7ff8000000000000, "+qNaN lo" }, { 0x7fffffffffffffff, "+qNaN hi" }, { 0x8000000000000000, "-zero " }, { 0x8000000000000001, "-denorm lo" }, { 0x800fffffffffffff, "-denorm hi" }, { 0x8010000000000000, "-norm lo" }, { 0xffefffffffffffff, "-norm hi" }, { 0xfff0000000000000, "-infinity " }, { 0xfff0000000000001, "-sNaN lo" }, { 0xfff7ffffffffffff, "-sNaN hi" }, { 0xfff8000000000000, "-IND ??" }, { 0xfff8000000000001, "-qNaN lo" }, { 0xffffffffffffffff, "-qNaN hi" } }; double asDouble( U64 u ) { return *(double*)&u; } int main( int argc, char **argv ) { char *s[] = { "NONE", "_EM_INEXACT", "_EM_DENORMAL", "_EM_INVALID" +, "_EM_ZERODIVIDE", "_EM_OVERFLOW", "_EM_UNDERFLOW" }; int m[] = { 0, _EM_INEXACT, _EM_DENORMAL, _EM_INVALID, _EM_ZERODIV +IDE, _EM_OVERFLOW, _EM_UNDERFLOW }; int i, j; for( j = 0; j < sizeof( pats ) / sizeof( FPCONST ); ++j ) { double d = asDouble( pats[j].b ); printf( "\nValue %s[%16I64x] as double:%16g ", pats[j].desc, p +ats[j].b, d ); for( i= 0; i < sizeof( m )/sizeof(int); ++i ) { printf( "\n\tWith %15.15s[%8x] exception enabled: ", s[i], + m[i] ); argc > 1 ? _control87( ~m[i], _MCW_EM ) : _controlfp( ~m[i +], _MCW_EM ); __try { printf( "*2:%16g ", d*2.0 ); } __except( 1 ) { printf( "*2: ** EXCEPTION ** " ); } __try { printf( "/2:%16g ", d/2.0 ); } __except( 1 ) { printf( "/2: ** EXCEPTION ** " ); } // printf( "\n" ); } } return 0; }

Output:

E:\femm42src\fkn\cui>floatException.exe Value +zero [ 0] as double: 0 With NONE[ 0] exception enabled: *2: + 0 /2: 0 With _EM_INEXACT[ 1] exception enabled: *2: + 0 /2: 0 With _EM_DENORMAL[ 80000] exception enabled: *2: + 0 /2: 0 With _EM_INVALID[ 10] exception enabled: *2: + 0 /2: 0 With _EM_ZERODIVIDE[ 8] exception enabled: *2: + 0 /2: 0 With _EM_OVERFLOW[ 4] exception enabled: *2: + 0 /2: 0 With _EM_UNDERFLOW[ 2] exception enabled: *2: + 0 /2: 0 Value +denorm lo[ 1] as double: 4.94066e-324 With NONE[ 0] exception enabled: *2: 9.881 +31e-324 /2: 0 With _EM_INEXACT[ 1] exception enabled: *2: 9.881 +31e-324 /2: ** EXCEPTION ** With _EM_DENORMAL[ 80000] exception enabled: *2: 9.881 +31e-324 /2: 0 With _EM_INVALID[ 10] exception enabled: *2: 9.881 +31e-324 /2: 0 With _EM_ZERODIVIDE[ 8] exception enabled: *2: 9.881 +31e-324 /2: 0 With _EM_OVERFLOW[ 4] exception enabled: *2: 9.881 +31e-324 /2: 0 With _EM_UNDERFLOW[ 2] exception enabled: *2: ** EXCEP +TION ** /2: ** EXCEPTION ** Value +denorm hi[ fffffffffffff] as double: 2.22507e-308 With NONE[ 0] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_INEXACT[ 1] exception enabled: *2: 4.450 +15e-308 /2: ** EXCEPTION ** With _EM_DENORMAL[ 80000] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_INVALID[ 10] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_ZERODIVIDE[ 8] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_OVERFLOW[ 4] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_UNDERFLOW[ 2] exception enabled: *2: 4.450 +15e-308 /2: ** EXCEPTION ** Value +norm lo[ 10000000000000] as double: 2.22507e-308 With NONE[ 0] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_INEXACT[ 1] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_DENORMAL[ 80000] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_INVALID[ 10] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_ZERODIVIDE[ 8] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_OVERFLOW[ 4] exception enabled: *2: 4.450 +15e-308 /2: 1.11254e-308 With _EM_UNDERFLOW[ 2] exception enabled: *2: 4.450 +15e-308 /2: ** EXCEPTION ** Value +norm hi[7fefffffffffffff] as double: 1.79769e+308 With NONE[ 0] exception enabled: *2: + 1.#INF /2: 8.98847e+307 With _EM_INEXACT[ 1] exception enabled: *2: ** EXCEP +TION ** /2: 8.98847e+307 With _EM_DENORMAL[ 80000] exception enabled: *2: + 1.#INF /2: 8.98847e+307 With _EM_INVALID[ 10] exception enabled: *2: + 1.#INF /2: 8.98847e+307 With _EM_ZERODIVIDE[ 8] exception enabled: *2: + 1.#INF /2: 8.98847e+307 With _EM_OVERFLOW[ 4] exception enabled: *2: ** EXCEP +TION ** /2: 8.98847e+307 With _EM_UNDERFLOW[ 2] exception enabled: *2: + 1.#INF /2: 8.98847e+307 Value +infinity [7ff0000000000000] as double: 1.#INF With NONE[ 0] exception enabled: *2: + 1.#INF /2: 1.#INF With _EM_INEXACT[ 1] exception enabled: *2: + 1.#INF /2: 1.#INF With _EM_DENORMAL[ 80000] exception enabled: *2: + 1.#INF /2: 1.#INF With _EM_INVALID[ 10] exception enabled: *2: + 1.#INF /2: 1.#INF With _EM_ZERODIVIDE[ 8] exception enabled: *2: + 1.#INF /2: 1.#INF With _EM_OVERFLOW[ 4] exception enabled: *2: + 1.#INF /2: 1.#INF With _EM_UNDERFLOW[ 2] exception enabled: *2: + 1.#INF /2: 1.#INF Value +sNaN lo[7ff0000000000001] as double: 1.#SNAN With NONE[ 0] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_INEXACT[ 1] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_DENORMAL[ 80000] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_INVALID[ 10] exception enabled: *2: ** EXCEP +TION ** /2: ** EXCEPTION ** With _EM_ZERODIVIDE[ 8] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_OVERFLOW[ 4] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_UNDERFLOW[ 2] exception enabled: *2: +1.#QNAN /2: 1.#QNAN Value +sNaN hi[7ff7ffffffffffff] as double: 1.#SNAN With NONE[ 0] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_INEXACT[ 1] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_DENORMAL[ 80000] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_INVALID[ 10] exception enabled: *2: ** EXCEP +TION ** /2: ** EXCEPTION ** With _EM_ZERODIVIDE[ 8] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_OVERFLOW[ 4] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_UNDERFLOW[ 2] exception enabled: *2: +1.#QNAN /2: 1.#QNAN Value +qNaN lo[7ff8000000000000] as double: 1.#QNAN With NONE[ 0] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_INEXACT[ 1] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_DENORMAL[ 80000] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_INVALID[ 10] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_ZERODIVIDE[ 8] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_OVERFLOW[ 4] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_UNDERFLOW[ 2] exception enabled: *2: +1.#QNAN /2: 1.#QNAN Value +qNaN hi[7fffffffffffffff] as double: 1.#QNAN With NONE[ 0] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_INEXACT[ 1] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_DENORMAL[ 80000] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_INVALID[ 10] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_ZERODIVIDE[ 8] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_OVERFLOW[ 4] exception enabled: *2: +1.#QNAN /2: 1.#QNAN With _EM_UNDERFLOW[ 2] exception enabled: *2: +1.#QNAN /2: 1.#QNAN Value -zero [8000000000000000] as double: -0 With NONE[ 0] exception enabled: *2: + -0 /2: -0 With _EM_INEXACT[ 1] exception enabled: *2: + -0 /2: -0 With _EM_DENORMAL[ 80000] exception enabled: *2: + -0 /2: -0 With _EM_INVALID[ 10] exception enabled: *2: + -0 /2: -0 With _EM_ZERODIVIDE[ 8] exception enabled: *2: + -0 /2: -0 With _EM_OVERFLOW[ 4] exception enabled: *2: + -0 /2: -0 With _EM_UNDERFLOW[ 2] exception enabled: *2: + -0 /2: -0 Value -denorm lo[8000000000000001] as double: -4.94066e-324 With NONE[ 0] exception enabled: *2: -9.881 +31e-324 /2: -0 With _EM_INEXACT[ 1] exception enabled: *2: -9.881 +31e-324 /2: ** EXCEPTION ** With _EM_DENORMAL[ 80000] exception enabled: *2: -9.881 +31e-324 /2: -0 With _EM_INVALID[ 10] exception enabled: *2: -9.881 +31e-324 /2: -0 With _EM_ZERODIVIDE[ 8] exception enabled: *2: -9.881 +31e-324 /2: -0 With _EM_OVERFLOW[ 4] exception enabled: *2: -9.881 +31e-324 /2: -0 With _EM_UNDERFLOW[ 2] exception enabled: *2: ** EXCEP +TION ** /2: ** EXCEPTION ** Value -denorm hi[800fffffffffffff] as double: -2.22507e-308 With NONE[ 0] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_INEXACT[ 1] exception enabled: *2: -4.450 +15e-308 /2: ** EXCEPTION ** With _EM_DENORMAL[ 80000] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_INVALID[ 10] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_ZERODIVIDE[ 8] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_OVERFLOW[ 4] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_UNDERFLOW[ 2] exception enabled: *2: -4.450 +15e-308 /2: ** EXCEPTION ** Value -norm lo[8010000000000000] as double: -2.22507e-308 With NONE[ 0] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_INEXACT[ 1] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_DENORMAL[ 80000] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_INVALID[ 10] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_ZERODIVIDE[ 8] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_OVERFLOW[ 4] exception enabled: *2: -4.450 +15e-308 /2: -1.11254e-308 With _EM_UNDERFLOW[ 2] exception enabled: *2: -4.450 +15e-308 /2: ** EXCEPTION ** Value -norm hi[ffefffffffffffff] as double: -1.79769e+308 With NONE[ 0] exception enabled: *2: +-1.#INF /2: -8.98847e+307 With _EM_INEXACT[ 1] exception enabled: *2: ** EXCEP +TION ** /2: -8.98847e+307 With _EM_DENORMAL[ 80000] exception enabled: *2: +-1.#INF /2: -8.98847e+307 With _EM_INVALID[ 10] exception enabled: *2: +-1.#INF /2: -8.98847e+307 With _EM_ZERODIVIDE[ 8] exception enabled: *2: +-1.#INF /2: -8.98847e+307 With _EM_OVERFLOW[ 4] exception enabled: *2: ** EXCEP +TION ** /2: -8.98847e+307 With _EM_UNDERFLOW[ 2] exception enabled: *2: +-1.#INF /2: -8.98847e+307 Value -infinity [fff0000000000000] as double: -1.#INF With NONE[ 0] exception enabled: *2: +-1.#INF /2: -1.#INF With _EM_INEXACT[ 1] exception enabled: *2: +-1.#INF /2: -1.#INF With _EM_DENORMAL[ 80000] exception enabled: *2: +-1.#INF /2: -1.#INF With _EM_INVALID[ 10] exception enabled: *2: +-1.#INF /2: -1.#INF With _EM_ZERODIVIDE[ 8] exception enabled: *2: +-1.#INF /2: -1.#INF With _EM_OVERFLOW[ 4] exception enabled: *2: +-1.#INF /2: -1.#INF With _EM_UNDERFLOW[ 2] exception enabled: *2: +-1.#INF /2: -1.#INF Value -sNaN lo[fff0000000000001] as double: -1.#SNAN With NONE[ 0] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_INEXACT[ 1] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_DENORMAL[ 80000] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_INVALID[ 10] exception enabled: *2: ** EXCEP +TION ** /2: ** EXCEPTION ** With _EM_ZERODIVIDE[ 8] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_OVERFLOW[ 4] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_UNDERFLOW[ 2] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN Value -sNaN hi[fff7ffffffffffff] as double: -1.#SNAN With NONE[ 0] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_INEXACT[ 1] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_DENORMAL[ 80000] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_INVALID[ 10] exception enabled: *2: ** EXCEP +TION ** /2: ** EXCEPTION ** With _EM_ZERODIVIDE[ 8] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_OVERFLOW[ 4] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_UNDERFLOW[ 2] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN Value -IND ??[fff8000000000000] as double: -1.#IND With NONE[ 0] exception enabled: *2: +-1.#IND /2: -1.#IND With _EM_INEXACT[ 1] exception enabled: *2: +-1.#IND /2: -1.#IND With _EM_DENORMAL[ 80000] exception enabled: *2: +-1.#IND /2: -1.#IND With _EM_INVALID[ 10] exception enabled: *2: +-1.#IND /2: -1.#IND With _EM_ZERODIVIDE[ 8] exception enabled: *2: +-1.#IND /2: -1.#IND With _EM_OVERFLOW[ 4] exception enabled: *2: +-1.#IND /2: -1.#IND With _EM_UNDERFLOW[ 2] exception enabled: *2: +-1.#IND /2: -1.#IND Value -qNaN lo[fff8000000000001] as double: -1.#QNAN With NONE[ 0] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_INEXACT[ 1] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_DENORMAL[ 80000] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_INVALID[ 10] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_ZERODIVIDE[ 8] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_OVERFLOW[ 4] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_UNDERFLOW[ 2] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN Value -qNaN hi[ffffffffffffffff] as double: -1.#QNAN With NONE[ 0] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_INEXACT[ 1] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_DENORMAL[ 80000] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_INVALID[ 10] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_ZERODIVIDE[ 8] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_OVERFLOW[ 4] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN With _EM_UNDERFLOW[ 2] exception enabled: *2: - +1.#QNAN /2: -1.#QNAN
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2016-10-01 19:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (6 votes). Check out past polls.