float and double data type
-
Hi, The value stored in Float and same value when stored in double there is difference in the value Why? Eg: void main() { CString str; union { float f1; unsigned long a1; }un1; union { double d_f1; unsigned long d_a1; }d_un1; float flt; double d_flt; un1.a1 = 0; un1.f1 = 0.0; un1.a1=0x6fffffff; flt = un1.f1; d_un1.d_a1 = 0; d_un1.d_f1 = 0.0; d_un1.d_a1=0x6fffffff; d_flt = d_un1.d_f1; } Output: d_flt 9.2837315805324e-315 flt 1.58456e+029 d_un1.d_f1 9.2837315805324e-315 un1.f1 1.58456e+029 I need the variable to hold value upto 0xffffffff as float cannot hold it i used double but there is a variation in the value if value is <7fffffffff.Is due to IEEE internal representation.HOw to resolve this. Thanks
-
Hi, The value stored in Float and same value when stored in double there is difference in the value Why? Eg: void main() { CString str; union { float f1; unsigned long a1; }un1; union { double d_f1; unsigned long d_a1; }d_un1; float flt; double d_flt; un1.a1 = 0; un1.f1 = 0.0; un1.a1=0x6fffffff; flt = un1.f1; d_un1.d_a1 = 0; d_un1.d_f1 = 0.0; d_un1.d_a1=0x6fffffff; d_flt = d_un1.d_f1; } Output: d_flt 9.2837315805324e-315 flt 1.58456e+029 d_un1.d_f1 9.2837315805324e-315 un1.f1 1.58456e+029 I need the variable to hold value upto 0xffffffff as float cannot hold it i used double but there is a variation in the value if value is <7fffffffff.Is due to IEEE internal representation.HOw to resolve this. Thanks
shir_k wrote:
I need the variable to hold value upto 0xffffffff as float
Why? I mean: cannot you use the unsigned integer instead?
shir_k wrote:
Is due to IEEE internal representation.HOw to resolve this
The above is true and there's nothing to resolve. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
shir_k wrote:
I need the variable to hold value upto 0xffffffff as float
Why? I mean: cannot you use the unsigned integer instead?
shir_k wrote:
Is due to IEEE internal representation.HOw to resolve this
The above is true and there's nothing to resolve. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Yes we can use unsigned integer but am more concerned about float value. Is any function in VC++ to convert hex value (0xffffffff) to equivalent float value. Thanks
shir_k wrote:
Is any function in VC++ to convert hex value (0xffffffff) to equivalent float value.
You cannot have such a function since the float value of 0xffffffff, according to IEEE 754 standard belongs to the NaN (Not a Number) set. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
shir_k wrote:
Is any function in VC++ to convert hex value (0xffffffff) to equivalent float value.
You cannot have such a function since the float value of 0xffffffff, according to IEEE 754 standard belongs to the NaN (Not a Number) set. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.