Click here to Skip to main content
14,494,016 members
Rate this:
Please Sign up or sign in to vote.
See more:
I know that max flotating point can be calculated by the above way:
Having 1.11111111111111111111111 (24 bits) then the decimal point moves the same number of places as the maximum exponent, therefore the maximum number is:
1111111111111111111111110000000000000000[..] (24 ones and (127 - 23 zeroes) resulting in a 128 bits number ) then i can get the maximum flotating point number:
(2^128-1) - (2^104-1) = 340282346638528859811704183484516925440.0
¿Why does 340282346638528859811704183484516925440.0 not appear in Codeblocks compiler?

What I have tried:

You can see the number printing FLT_MAX macro on GDB online Debugger | Compiler - Code, Compile, Run, Debug online C, C++[^] but not in codeblocks compiler :
https://i.ibb.co/zQXzNFH/flt-max.png
Posted
Updated 25-Mar-20 5:55am
v4
Comments
Richard MacCutchan 25-Mar-20 8:00am
   
Do you have a question?
Patrice T 25-Mar-20 10:35am
   
And you have a question ?
Rate this:
Please Sign up or sign in to vote.

Solution 2

I suppose it is an artifact of the %f specifier.
Try to use %a on both the systems.
   
v2
Comments
Xargam 25-Mar-20 11:31am
   
Both systems print a hexadecimal number
CPallini 25-Mar-20 11:35am
   
The important question is: "do both the systems print the same hex string?"
Xargam 25-Mar-20 11:43am
   
yes, they do.
CPallini 25-Mar-20 11:48am
   
So, they ARE the same. That is the binary pattern in memory is exactly the same (the one you expect, I guess). The different output is due to the different implementations of the printf %f specifier handling.
Stefan_Lang 25-Mar-20 12:13pm
   
I hadn't expected it's printf - have a 5!
CPallini 25-Mar-20 16:36pm
   
Thank you very much, Stefan. And have my five as well.
Xargam 25-Mar-20 12:55pm
   
Great! Thanks!
CPallini 26-Mar-20 11:17am
   
You are welcome.
Rate this:
Please Sign up or sign in to vote.

Solution 3

The number you came up with may or may not be FLT_MAX. The Standard for C specifies that the language should provide the value FLT_MAX, but it doesn't require that this value is the same for every compiler. The actual value depends on the format that the compiler uses to store a float value.

Do not assume this value stays the same when using a different compiler. Do not make any assumptions what that format is: if you must know, you should refer to the compiler documentation. But your programs should not use that knowledge.
   
v2
Comments
CPallini 25-Mar-20 9:32am
   
"you'd need 33 bits to store it with room for a sign bit"
Nope. The 1 to the left of the decimal point is implicit. See
https://en.wikipedia.org/wiki/IEEE_754
Stefan_Lang 25-Mar-20 9:51am
   
You are correct, I was wondering about that and looked it up. Fixed my statement, although, since most compilers nowadays use IEEE, it might not be *the* answer the OP was looking for.
Xargam 25-Mar-20 11:40am
   
I do not have compiler documentation.Is it possible to find?Is it usually public?
Stefan_Lang 25-Mar-20 11:50am
   
It should come with the compiler: if it offers a graphical user interface, you can probably access it with the F1 key, or via Help menu.

It might also be public, but a quick search on "Codeblocks floating point format" turned up empty. :-( Maybe different keywords would help.
Stefan_Lang 25-Mar-20 12:00pm
   
P.S.: I've found some documentation here: http://www.codeblocks.org/user-manual

Unfortunately no word on floating point representation.
Xargam 25-Mar-20 12:54pm
   
Thank you very much for following!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100