Author Topic: "Exact" 80-bit decimal number  (Read 922 times)

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
"Exact" 80-bit decimal number
« on: February 18, 2019, 11:02:57 PM »
Different floating point numbers will resolve to the same 80 bit floating point register contents. This is due to precision and rounding errors.
However, a given 80 bit floating point register contents resolves to one and only one floating point number or its decimal representation.
Sounds complicated? Yes, it does, but only at first sight.
What the attached code does is convert the contents of the 80 bit register to its "exact" decimal representation.
The "exact" representation can not do better than the 18-20 significant digits that 80 bit IEEE floats can provide, but is guaranteed to have those 18-20 significant digits in the result.

The heart of the code is based on JackTrapper original Delphi code mentioned here:
https://stackoverflow.com/questions/50975653/convert-extended-80-bit-to-string which is licensed under the The Unlicense (A license with no conditions whatsoever which dedicates works to the public domain. Unlicensed works, modifications, and larger works may be distributed under different terms and without source code.). At this time, I am not going to supply the source for my version  of JackTrapper code, because 1) I have some further use for it and 2) it may end inside some undocumented library or 3) used by some people that never provide source code or credit where they got it.  :badgrin:

Otherwise, the attachment contains the .exe and everything to build it. It is expected to work in Windows 2000 and above (tested in Windows 2000 and Windows 10). The .exe is less than 5 Kb.

Below image from Windows 2000:  :biggrin:



edited 21st Feb: Required fixes in the code, attachment re-uploaded.
« Last Edit: February 21, 2019, 07:40:39 PM by AW »

guga

  • Member
  • *****
  • Posts: 1074
  • Assembly is a state of art.
    • RosAsm
Re: "Exact" 80-bit decimal number
« Reply #1 on: February 19, 2019, 12:04:02 AM »
Nice work, AW :t

Btw, what does the term "Unorm" means ? Are they the subnormal/denormalized numbers ?

Did you read he articles i posted on posit ? Maybe it would be an valid alternative to IEEE Fpu (Seems to produce no NANs, whatsoever) 8)

https://supercomputingfrontiers.eu/2017/wp-content/uploads/2017/03/2_1100_John-Gustafson.pdf
https://github.com/libcg/bfp
https://posithub.org/docs/PositTutorial_Part1.html
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
Re: "Exact" 80-bit decimal number
« Reply #2 on: February 19, 2019, 03:27:38 AM »
Btw, what does the term "Unorm" means ? Are they the subnormal/denormalized numbers ?

Unorm is very likely a "typo". Ollydbg calls it that way, or better calls it UNORM.
Intel calls it Unnormal when it refers to "Unsupported Double Extended-Precision
Floating-Point Encodings and Pseudo-Denormals". Since I had no other name, Windbg and Visual Studio give it no name, I called it Unorm.

Quote
Did you read the articles i posted on posit ? Maybe it would be an valid alternative to IEEE Fpu (Seems to produce no NANs, whatsoever)

May be, but without hardware supporting it we are in the realm of future possibilities.


dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: "Exact" 80-bit decimal number
« Reply #3 on: February 19, 2019, 07:11:07 AM »
i wrote a similar program some time back
it evaluates 4, 8, or 10-byte reals
by adding the "P" switch to the command line, it shows the value at full precision

http://masm32.com/board/index.php?topic=222.msg19324#msg19324

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
Re: "Exact" 80-bit decimal number
« Reply #4 on: February 19, 2019, 07:33:10 AM »
i wrote a similar program some time back
it evaluates 4, 8, or 10-byte reals
by adding the "P" switch to the command line, it shows the value at full precision

http://masm32.com/board/index.php?topic=222.msg19324#msg19324

Great work indeed.  :t

Something I will do sometime, or may be is already done by someone, is the opposite: Input a string representing a Real10 and produce a Real10 from it.

jj2007

  • Member
  • *****
  • Posts: 9786
  • Assembler is fun ;-)
    • MasmBasic
Re: "Exact" 80-bit decimal number
« Reply #5 on: February 19, 2019, 10:35:31 AM »
Something I will do sometime, or may be is already done by someone, is the opposite: Input a string representing a Real10 and produce a Real10 from it.

include \masm32\MasmBasic\MasmBasic.inc                 ; download
include \masm32\MasmBasic\Res\QuadMath.inc     

  SetGlobals num16:REAL16, num10:REAL10         ; define two global variables

  Init quad                                     ; initialise
  Let esi="3.14159265358979323846264338327950"
  PrintLine "digits", Tb$, "1.23456789012345678901234567890123"  ; show how many digits are precise
  PrintLine "PI", Tb$, esi, Tb$, "(as text)"
  MovVal num16, esi                     ; convert text->REAL16
  PrintLine "PI16", Tb$, Str$(num16), Tb$, "Real16 precision"    ; convert REAL16->text
  MovVal num10, esi                     ; convert text->REAL10
  Inkey "PI10", Tb$, Str$(num10), Tb$, Tb$, "Real10 precision"   ; convert REAL10->text
EndOfCode


Output:
Code: [Select]
digits  1.23456789012345678901234567890123
PI      3.14159265358979323846264338327950      (as text)
PI16    3.14159265358979323846264338327950e+00  Real16 precision
PI10    3.141592653589793239            Real10 precision

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
Re: "Exact" 80-bit decimal number
« Reply #6 on: February 19, 2019, 02:56:53 PM »
include \masm32\MasmBasic\MasmBasic.inc                 ; download
include \masm32\MasmBasic\Res\QuadMath.inc     
I know how it works.
The association of the undocumented closed source Masm Basic and GCC to produce bloatware is terrific, however the function StrToFloat is available in Delphi and Free Pascal since long with full source code in both Pascal and ASM. 

guga

  • Member
  • *****
  • Posts: 1074
  • Assembly is a state of art.
    • RosAsm
Re: "Exact" 80-bit decimal number
« Reply #7 on: February 19, 2019, 06:42:57 PM »
Tks.. :t :t :t
Quote
May be, but without hardware supporting it we are in the realm of future possibilities.

 But..what hardware ? I thought that posit was created to be used in any processor. The library seems to work ok. I´l test it eventually (if it is working). The only problem will be porting it to assembly, since it is written in Arghhhhh C++ :icon_mrgreen: :icon_mrgreen: :icon_mrgreen:
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
Re: "Exact" 80-bit decimal number
« Reply #8 on: February 19, 2019, 07:27:13 PM »
Tks.. :t :t :t
Quote
May be, but without hardware supporting it we are in the realm of future possibilities.

 But..what hardware ? I thought that posit was created to be used in any processor. The library seems to work ok. I´l test it eventually (if it is working). The only problem will be porting it to assembly, since it is written in Arghhhhh C++ :icon_mrgreen: :icon_mrgreen: :icon_mrgreen:
And why use Posit when we can use MPFR? It works great from MASM, was in large part developed in ASM, is extremely fast and has unlimited precision.   :biggrin:  :biggrin: :biggrin:

daydreamer

  • Member
  • ****
  • Posts: 939
  • watch Chebyshev on the backside of the Moon
Re: "Exact" 80-bit decimal number
« Reply #9 on: February 20, 2019, 12:06:47 AM »
what about TI's own floating point format on their calculators?
its easy to read/write to fp variables in memory because the format is mostly packed BCD

I dont know if it was masm or some other assembler had directives for the days before x87 was standard included in cpu,to tell the assembler to emit calls to fpu emulator lib instead of generating the usual x87?
maybe an alternative to make your code use a faster library than fpu,instead of need total rewrite of your code?
 
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D

dedndave

  • Member
  • *****
  • Posts: 8823
  • Still using Abacus 2.0
    • DednDave
Re: "Exact" 80-bit decimal number
« Reply #10 on: February 20, 2019, 12:51:59 AM »
back in the day, MS had their own floating point formats for single and double precision
they were used in MS Basic, for example (possibly other compilers, like Fortran, etc)

the formats were quite similar to "Intel Floats" (now known as IEEE-754)
MS Floats had one bit more precision, but one bit less range
i seem to recall the sign bit was moved
also, they did not allow for NaN's, infinity, or underflow

https://en.wikipedia.org/wiki/Microsoft_Binary_Format