View Full Version : Precision issues with comparing Floats and Integers
jmac698
10th November 2011, 00:45
I thought I had this clear, that I can use 23, 64, and 112 as a portable standard. Now you're saying that the exception is long double<>quad. Ok, I can handle one exception.
Gavino
10th November 2011, 00:47
For a given C implementation, the header files limits.h and float.h define various properties (ranges, etc) of int, float and double.
amtm
10th November 2011, 00:51
I thought I had this clear, that I can use 23, 64, and 112 as a portable standard. Now you're saying that the exception is long double<>quad. Ok, I can handle one exception.
I only told you the sizes for float and double. But, yes, like Gavino says you can use float.h and the FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG to get the sizes if you are that worried.
jmac698
10th November 2011, 00:58
Those aren't present in mingw. The only thing close is just for int's, so no there is no portable way to do it.
/*
* Maximum and minimum values for ints.
*/
#define INT_MAX 2147483647
#define INT_MIN (-INT_MAX-1)
#define UINT_MAX 0xffffffff
amtm
10th November 2011, 01:03
There is something wrong with MinGW then. Secondly, you keep mentioning "no portable way" but do you actually know of any mainstream C or C++ implementation that uses some other format than IEEE-754 single-precision and double-precision floats for float and double respectively?
amtm
10th November 2011, 01:15
To further add, the FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG macros being defined in float.h is part of the C89 standard. If MinGW doesn't have those macros then something is seriously broken in their C standard library.
jmac698
10th November 2011, 01:37
You're right, FLT_MANT_DIG etc. is the proper way to do it, and still can't find them in mingw, so yes it's broken.
The equivalent for int is stdint.h
I found out there's a system with a 32bit char.
There's no specific guaranteed sizes in C.
This explains it well
http://stackoverflow.com/questions/589575/size-of-int-long-etc
Gavino
10th November 2011, 01:48
You're right, FLT_MANT_DIG etc. is the proper way to do it, and still can't find them in mingw, so yes it's broken.
I believe they are built into the GCC compiler (though you still have to include float.h) - have you tried using them in a program?
Gavino
10th November 2011, 02:06
If a binary operator is applied to an int and a float, the int is first converted to float, as in C.
I've added this to the wiki:
http://avisynth.org/mediawiki/Operators
amtm
10th November 2011, 02:24
There's no specific guaranteed sizes in C.
Great, but again can you name a single implementation of C or C++ that uses anything but IEEE-754 single-precision or double-precision floating point formats? We can talk all day about theory, but if you can't name a single one in practice the point is completely moot. I'm wondering exactly which platform you think you are going to make a piece of software for that this doesn't hold true for. So, yes, to do things properly use the macros, but I'm pretty sure in practice you will never see those values be anything but 24 or 53 unless you are planning on using some completely exotic platform where the people implementing the C or C++ standard library or the hardware FPU chose for some reason to not use the prevailing standard for floating point numbers.
jmac698
10th November 2011, 02:44
If you say so, I believe you.
So I won't worry about it.
I just didn't know, I was just asking.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.