(nearly) ieee 754 floating point single precisition

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: (nearly) ieee 754 floating point single precisition

#46 Post by einstein1969 » 25 May 2024 07:48

thanks.

I got to the point

"divide h.ighlow by 2 (updating the e_2 value) until 1 <= h.ighlow < 2".

Code: Select all

         set "string= 8   4 2 "
         for %%a in ("!high:~0,1!") do @for %%b in (!string:~-%%~a!) do @(
            >nul set /A "c=(high&1)+1"
            set "low=!c!!low!"
            >nul set /A "high>>=1", "low=(low>>1)-50000000", "e_2+=1"
            set "low=00000000!low!"
            set "low=!low:~-8!"
         )
Can you explain these two instructions to me, the first I don't understand why you do set /A "c=(high&1)+1" and

I don't understand why in this set /A "high>>=1", "low=(low >>1)-50000000", "e_2+=1" remove 50000000 from low/2.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: (nearly) ieee 754 floating point single precisition

#47 Post by penpen » 25 May 2024 14:15

When i divide high by 2 (realized by high>>=1), then there is an underflow in case high contains an odd number.
I don't want to lose that underflowed portion, so i force it to be the leading character of low (low=!c!!low!).
But if the leading character of low is 0, then the set/a-command treats low as an octal number.
Therefore i have to make sure it's not zero, hence i added 1, resulting in "c=(high&1)+1".
To not change the value, I have to substract the value I've added (or half of the value, once i divided by 2) and
I also have to increase the exponent to the basis of two by one, resulting in ""high>>=1", "low=(low>>1)-50000000", "e_2+=1"".
The last two lines ensure that low contains exactly 8 digits.


penpen

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: (nearly) ieee 754 floating point single precisition

#48 Post by einstein1969 » 27 May 2024 17:22

ok, I was going crazy to figure out that +1.

These days I've had to slow down because my only PC is having problems and isn't working well.

Post Reply