473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

IEEE floating point

Hi,

I am not really sure wether there is a better group for this. I already
tried a VC group, but they cannot tell me how other stdlibs are doing
it.

I tested a lot with inf and NaNs. I read some docs from docs.sun.com
about the standard. It seems to be an commented inerpretation of the
IEEE standard.

So it seems my VC.net's standard c++ library is not really meeting the
standard, or the standard is not what I think.

I found out that:

the numeric_limits<double> knows only a infinite which is the standards
+inf.

it knows a sNaN which is different from the one in the standard, it is
rather the same as the standards -inf

if I calculate d = d / 0 I get what numeric_limit says is the sNaN. This
is fine even though the bit pattern is different from the standard, but
I can use it just as is.

But, d = -d * d returns the same bit pattern. In this case it is
returning the standards -inf as ist should, but there is no -inf in the
numeric_limits of the library.

All in all the behaviour is weird, but the only problem is, that I can
not distinguish between -inf and sNaN. Whis is in case of some matrix
caclulations the difference between division by zero and division by
some very small ( neg ) number.

Is someone familiar with this topic, or can tell me about his version of
the stdlib or compiler, or can point me to another interpretation of the
IEEE standard?

Here is the code that I used to examine the problem:

#include <iostream>

#include <math.h>

#include <limits>

using namespace std;
const __int64 NAN_BITS = 0x7ff0000000000000;
bool IsNAN( const double d )
{
return ( ( *reinterpret_cast<const __int64*>( &d ) & NAN_BITS ) ==
NAN_BITS )
&& ( *reinterpret_cast<const __int64*>( &d ) != NAN_BITS );
}
void hexout( void* p )
{
cout << "\t";
cout.width( 8 );
cout.fill( '0' );
long* pl = (long*)p;
cout << hex << pl[1] << " ";
cout.width( 8 );
cout.fill( '0' );

cout << hex << pl[0] << endl;
}

template< typename T >
void report( )
{

cout << "numeric_limits<double>::\n" << endl;

double
d = numeric_limits<T>::denorm_min( ); cout << "denorm_min = ";

hexout( &d );
// d = numeric_limits<T>::denorm_max( ); cout << "denorm_max = ";

// hexout( &d );

d = numeric_limits<T>::epsilon( ); cout << "epsilon = ";

hexout( &d );
d = numeric_limits<T>::infinity( ); cout << "infinity = ";
hexout( &d );
// cout << "is_bounded = " << numeric_limits<T>::is_bounded( ) <<
endl;
// cout << "is_exact = " << numeric_limits<T>::is_exact( ) << endl;
// cout << "is_iec559 = " << numeric_limits<T>::is_iec559( ) << endl;

d = numeric_limits<T>::max( ); cout << "max =
\t";
hexout( &d );

d = numeric_limits<T>::min( ); cout << "min =
\t";
hexout( &d );
d = numeric_limits<T>::quiet_NaN( );cout << "quiet_NaN = ";
hexout( &d );
d = numeric_limits<T>::signaling_NaN( );cout << "signaling_NaN =
";
hexout( &d );

// produce an infinite number:
d = numeric_limits<T>::max( ); d = d * d;cout << "pos inf = \t";
hexout( &d );
cout << "Is positive infinity NaN ? " << IsNAN( d ) << endl;

d = numeric_limits<T>::max( ); d = -d * d;cout << "neg inf = \t";
hexout( &d );
cout << "Is negative infinity NaN ? " << IsNAN( d ) << endl;

d = d / 0;
cout << "Div by zero returns: "; hexout( &d );

cout << "Is div by zero NaN ? " << IsNAN( d ) << endl;

}
int main(int argc, char* argv[])
{

report< double >( );

cout << endl << endl;
cout << "sizeof( float ) = " << sizeof( float ) << endl;
cout << "sizeof( double ) = " << sizeof( double ) << endl;
cout << "sizeof( long double ) = " << sizeof( long double ) <<
endl;
getchar( );
return 0;
}
Jul 22 '05 #1
2 2468
"Ingo Nolden" <nu************@SPAMgmx.de> wrote in message
news:Xn***************************@62.245.150.226. ..
I tested a lot with inf and NaNs. I read some docs from docs.sun.com
about the standard. It seems to be an commented inerpretation of the
IEEE standard.

So it seems my VC.net's standard c++ library is not really meeting the
standard, or the standard is not what I think.

I found out that:

the numeric_limits<double> knows only a infinite which is the standards
+inf.

it knows a sNaN which is different from the one in the standard, it is
rather the same as the standards -inf


Yep, it's a bug. Fixed in later releases.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #2
"P.J. Plauger" <pj*@dinkumware.com> wrote in
news:Ae*******************@nwrddc03.gnilink.net:
"Ingo Nolden" <nu************@SPAMgmx.de> wrote in message
news:Xn***************************@62.245.150.226. ..

it knows a sNaN which is different from the one in the standard, it
is rather the same as the standards -inf


Yep, it's a bug. Fixed in later releases.


And I should have checked with the newest release I have. Indeed, in
VC.net2003 it is correct. And what I used before was not VS.net as said,
but VS6.0, so sorry and thanks.

Ingo
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Mad Butch | last post by:
void Test() { float fValue = 0.5678f; // Value is 0.567800 double dValue = (double)fValue; // Value is 0.56779998540878 } Is there anyway I can round a float at 6 positions behind the...
11
by: Grant Edwards | last post by:
I've read over and over that Python leaves floating point issues up to the underlying platform. This seems to be largely true, but not always. My underlying platform (IA32 Linux) correctly...
2
by: Madhusudan Singh | last post by:
I am querying an instrument in a measurement application. The values are returned as IEEE format binary floating point numbers. There are 4 bytes per point. Multiple points are not separated by...
1
by: GooglePoster | last post by:
Hello, I am looking for a function/utility to read in an IEEE value and convert this to decimal, for testing purposes. Also, I need to convert decimal values to IEEE values to send out on a...
54
by: Andy | last post by:
Hi, I don't know if this is the correct group to post this, but when I multiply a huge floating point value by a really small (non-zero) floating point value, I get 0 (zero) for the result. This...
2
by: Benjamin Rutt | last post by:
Does anyone have C code laying around to do this? I have to read in some binary data files that contains some 4-byte IBM/370 floating point values. I would like a function to convert 4-byte...
2
by: Andre | last post by:
I read some place that for performance reasons, IEEE floating point standard has not been implemented by .NET and that different machine architectures may produce different results.. but what if...
33
by: Nick Maclaren | last post by:
The numerical robustness of Python is very poor - this is not its fault, but that of IEEE 754 and (even more) C99. In particular, erroneous numerical operations often create apparently valid...
1
by: Faezeh | last post by:
I want to read 4 byte with IEEE floating point format and convert to decimal number in vb.net, and need to function for shift bits to left in vb .net. 32 bit IEEE floating point has this format: ...
13
by: revuesbio | last post by:
Hi Does anyone have the python version of the conversion from msbin to ieee? Thank u
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.