Author Topic: output 80-bits number from the FPU to the console  (Read 32163 times)

Mikl__

  • Member
  • *****
  • Posts: 1346
output 80-bits number from the FPU to the console
« on: March 19, 2013, 10:15:12 PM »
Hello! Please, tell me how to display 80-bit number from the FPU to the console?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: output 80-bits number from the FPU to the console
« Reply #1 on: March 19, 2013, 10:37:24 PM »
As we don't do "requests", show us your code first.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: output 80-bits number from the FPU to the console
« Reply #2 on: March 19, 2013, 11:11:03 PM »
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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: output 80-bits number from the FPU to the console
« Reply #3 on: March 20, 2013, 12:01:56 AM »
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

  • Member
  • ****
  • Posts: 820
Re: output 80-bits number from the FPU to the console
« Reply #4 on: March 20, 2013, 04:36:34 AM »
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__

  • Member
  • *****
  • Posts: 1346
Re: output 80-bits number from the FPU to the console
« Reply #5 on: March 20, 2013, 01:23:23 PM »
Quote
As we don't do "requests", show us your code first.
Code: [Select]
; 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

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: output 80-bits number from the FPU to the console
« Reply #6 on: March 20, 2013, 02:03:54 PM »
Hi! 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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: output 80-bits number from the FPU to the console
« Reply #7 on: March 20, 2013, 02:39:47 PM »
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

  • Guest
Re: output 80-bits number from the FPU to the console
« Reply #8 on: March 20, 2013, 02:49:55 PM »
May be exist decompress compress decimal theory and established optimal algorythm?
Quote
TW   "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__

  • Member
  • *****
  • Posts: 1346
Re: output 80-bits number from the FPU to the console
« Reply #9 on: March 20, 2013, 04:30:38 PM »
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!


dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave

Mikl__

  • Member
  • *****
  • Posts: 1346
Re: output 80-bits number from the FPU to the console
« Reply #12 on: March 20, 2013, 09:06:52 PM »
Quote from: dedndave
google translate is not very nice
excuse me for my english

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: output 80-bits number from the FPU to the console
« Reply #13 on: March 20, 2013, 09:11:19 PM »
you are ok   :t

bomz is scaring me, a little - lol

Mikl__

  • Member
  • *****
  • Posts: 1346
Re: output 80-bits number from the FPU to the console
« Reply #14 on: March 20, 2013, 09:54:50 PM »
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.