Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ SSE and SSE2 compiler settings, and their Floating Point effects.

Status
Not open for further replies.

S122

Programmer
May 31, 2022
1
0
0
AU
I have been running C++ floating point tests using the Twilight Dragon Media
C++ compiler for 64 bit Windows 10.

[URL unfurl="true"]https://jmeubank.github.io/tdm-gcc/[/url]

C++ starts by using IEEE 754 equation for floats and doubles, decimal and
hexadecimal values, floating point arithmetic, if I have things right. See this at:

[URL unfurl="true"]https://introcs.cs.princeton.edu/java/91float/[/url]

I have learned that when you compile in
Code:
A)
float a = 0.1F;

what you get is stored is

0.100000001490116119384765625


whereas when you compile in

Code:
B)
double b = 0.1D;

what you get stored is

0.1000000000000000055511151231257827021181583404541015625

Most of your floating point operators are these:


+, -, *, /, %, ++n, --n, n++, n--, +=, -=, *=, /=, %=


Is there a GNU C++ switch that will turn off all of these floating point overflow
and underflow values, both for assignment of the floating point data and arithmetic
operator calculation for separate floating point data, too? How can this be acheived
without adjusting the floating point source code at all?
 
32-bit floats are single precision and are only accurate to 6 SF.
64-bit doubles are double precision and are only accurate to 15 SF.

Anything else beyond those limits are just rubbish. The rubbish may be different on every machine.

The following wiki articles have more details

floats
doubles

Can't answer your question about g++.
 
If you're on an 80486DX or later CPU, or have an 8087 or 80387 FPU, or are on an AMD64 machine, the FPU supports an IEEE-754 80-bit floating point format as well. It affords 18-19 significant digits.

There may be intrinsics for it. I've always coded directly in assembly.

--
Rick C. Hodgin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top