News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

"Exact" 80-bit decimal number

Started by aw27, February 18, 2019, 11:02:57 PM

Previous topic - Next topic

aw27

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.

guga

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

aw27

Quote from: guga on February 19, 2019, 12:04:02 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

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

aw27

Quote from: dedndave 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

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

Quote from: AW on February 19, 2019, 07:33:10 AMSomething 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:
digits  1.23456789012345678901234567890123
PI      3.14159265358979323846264338327950      (as text)
PI16    3.14159265358979323846264338327950e+00  Real16 precision
PI10    3.141592653589793239            Real10 precision

aw27

Quote from: jj2007 on February 19, 2019, 10:35:31 AM
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

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

aw27

Quote from: guga 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:
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

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?
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

dedndave

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