News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

output 80-bits number from the FPU to the console

Started by Mikl__, March 19, 2013, 10:15:12 PM

Previous topic - Next topic

Mikl__

Hello! Please, tell me how to display 80-bit number from the FPU to the console?

hutch--

As we don't do "requests", show us your code first.

jj2007

Seeing your code would be nice indeed ;-)

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  fld1
  fldl2e
  fldl2t
  fldlg2
  fldln2
  fldpi
  ; with deb macro:
  deb 4, "Debug macro:", ST(0), ST(1), ST(2), ST(3), ST(4), ST(5)
  ; with ordinary Str$():
  Inkey Str$("PI=%Jf", ST(0))
  fstp st        ; don't forget to clear the FPU
  Exit
end start

Output:
Debug macro:
ST(0)           3.14159265358979324
ST(1)           0.693147180559945309
ST(2)           0.301029995663981195
ST(3)           3.32192809488736235
ST(4)           1.44269504088896341
ST(5)           1.00000000000000000
PI=3.141592653589793238

dedndave

understand the number format
understand base conversion
after that, it's a matter of whether you want it to be fast or not
speed may not be a real issue (pun)   :P

RuiLoureiro

Quote from: Mikl__ on March 19, 2013, 10:15:12 PM
Hello! Please, tell me how to display 80-bit number from the FPU to the console?

Hi
        convert that 80-bit number to string and print it.
        It's not easy to do. you can find a library Math10
        here in the forum that do it
       

Mikl__

QuoteAs we don't do "requests", show us your code first.
; masm windows gui #
.686P
.model flat
include \masm32\include\windows.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\fpulib\fpu.lib
include \masm32\fpulib\fpu.inc
;--------------------------------------------------
.data
result dt ?
szBuffer db 100 dup(0)
.code
start: finit
fldpi
fstp result
invoke  FpuFLtoA, ADDR result,40,ADDR szBuffer,SRC1_REAL Or SRC2_DIMM
        invoke MessageBox, NULL, addr szBuffer, 0, MB_OK
    retn
end start
Hi! function FpuFLtoA from masm32/fpulib displays only 15 digits maximum, and I would like to have 31 as a Windows-calculator

qWord

Quote from: Mikl__ on March 20, 2013, 01:23:23 PMHi! function FpuFLtoA from masm32/fpulib displays only 15 digits maximum, and I would like to have 31 as a Windows-calculator
you probably won't find any solution that produce more than 19 or 20 digits, because the 80Bit format does not allow higher precisions (64 precision bits --> lg(2^64) = 19.3 ).
If you really need 31 digits, you must use a high/arbitrary precision library.
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

qWord is absolutely correct
precision of 31 decimal digits will reguire something in the order of 100 bits binary
you can find 128 bit libraries, usually called big num or arbitrary lib's

i have sometimes wondered how hard it might be to use double-precision FPU calculations, though
we could apply the same techniques we use to extend x86 instructions   :P
even then, you might be limited in divisor size

bomz

May be exist decompress compress decimal theory and established optimal algorythm?
QuoteTW   "000102030405060708090A0B0C0D0E0F", compressdecimaltable
TW   "101112131415161718191A1B1C1D1E1F"
TW   "202122232425262728292A2B2C2D2E2F"
TW   "303132333435363738393A3B3C3D3E3F"
TW   "404142434445464748494A4B4C4D4E4F"
TW   "505152535455565758595A5B5C5D5E5F"
TW   "606162636465666768696A6B6C6D6E6F"
TW   "707172737475767778797A7B7C7D7E7F"
TW   "808182838485868788898A8B8C8D8E8F"
TW   "90919293949596979899";9A9B9C9D9E9F"
..........................................................................
FString            db 40 dup(?)
CReg            dt ?
..........................................................................
   fbstp CReg
   lea esi,CReg
   lea edi,FString+32
   mov ecx, 9
next:
   xor eax, eax
   lodsb
   shl eax, 2
   add eax, offset compressdecimaltable
   mov eax, dword ptr[eax]
   mov dword ptr[edi], eax
   sub edi, 4
   loop next
   invoke MessageBoxW,0,addr FString,0,MB_OK + MB_ICONASTERISK

Mikl__

qWord,
Thanks for the clarification
dedndave,
You are right, lg(2128)=38.531839444989592987358578524735 I could calculate it in advance
bomz,
I would like to discuss it in our native language

Many thanks to all!

bomz

http://forum.ru-board.com/topic.cgi?forum=33&bm=1&topic=3174&glp#lt

dedndave

Quote from: bomz on March 20, 2013, 04:37:20 PM
http://forum.ru-board.com/topic.cgi?forum=33&bm=1&topic=3174&glp#lt

google translate is not very nice   :lol:

Mikl__

Quote from: dedndavegoogle translate is not very nice
excuse me for my english

dedndave

you are ok   :t

bomz is scaring me, a little - lol

Mikl__

dedndave,
to me wrote about the Windows-calculator that in it uses its own implementation of long numbers, rather than the standard built-in types.