Rounding numbers in MT4 via NormalizeDouble - page 17

 
pavlick_:

I wrote a little training code (I was interested in poking around myself) which turns out the insides of the floating number.

The output at f == 0.5 + 1/(2^24). 1/(2^24) is the youngest digit of the mantissa at a given degree:

What exactly did you want to see there? Float numbers have one bit per sign, 8 bits per exponent, and the remaining 23 are mantissa, i.e. the maximum precision is 23 decimal places in binary representation, or 7 decimal places. For double numbers, there is 1 bit per sign, 11 bits per exponent, the remaining 52 bits are mantissa, maximum precision is 52 decimal places in binary representation or 16 decimal places. Why is there a code for this?

 
Sergei Vladimirov:

What exactly did you want to see there? Float numbers have one bit per sign, 8 bits per exponent, the remaining 23 are mantissa, i.e. the maximum accuracy of 23 decimal places in binary representation, or 7 decimal places. For double numbers, there is 1 bit per sign, 11 bits per exponent, the remaining 52 bits are mantissa, maximum precision is 52 decimal places in binary representation or 16 decimal places. Why is there a code for this?

"Theory without practice is dead and fruitless, practice without theory is useless and pernicious." And all sorts of interesting things with floating numbers abound:
float a, b, f;
a=123456789;
b=123456788;    
f=a-b;
cout << f;
// cout: 8
 
pavlick_:
"Theory without practice is dead and fruitless, practice without theory is useless and detrimental." And there's all sorts of interesting stuff with floating numbers:

I just thought that maybe you were expecting something unique in MKL.

And the whole mantissa overflow thing is interesting. For first grade. )

void OnStart()
{
        float f1 = (float)1.1;
        float f2 = (float)2.2;
        float f3 = (float)3.3;
        
        if((f1 * f2) * f3 == f1 * (f2 * f3))
                Print("Выражения равны.");
        else
                Print("Нифига не равны!");
}
 
For the first grade. )
Sure, tell us, most programmers are not up to speed on the subject, and I have some gaps myself.
 
pavlick_:
Of course, tell me, most programmers are not up to speed on the subject, I have some gaps myself.
Well, I don't know, we were trained in binary arithmetic so that it stuck in our heads for life. ) Another thing is that not all of us are programmers. In general, you do not think that my question is some kind of stone in your garden, I just thought that the purpose of your program - to see some differences in the MCL from the standard, so I asked.
 
int main(){
  // МКЛ аналог numeric_limits<float>::epsilon() - FLT_EPSILON
  float a = (float)10 + numeric_limits<float>::epsilon();
  float b = (float)1 + numeric_limits<float>::epsilon();
  float c = (float)0.5 + numeric_limits<float>::epsilon();
  print_float(a);
  print_float(b);
  print_float(c);
}

----a--------------
value = 10
mantissa 24:
1,01000000000000000000000
exponenta - 127 = 3

мантиса без прибавки эпсилон:
1,01000000000000000000000
----b--------------
value = 1.0000001192092896
mantissa 24:
1,00000000000000000000001
exponenta - 127 = 0

мантиса без прибавки эпсилон:
1,00000000000000000000000
----c--------------
 value = 0.50000011920928955
mantissa 24:
1,00000000000000000000010
exponenta - 127 = -1

мантиса без прибавки эпсилон:
1,00000000000000000000000
Reason: