News:

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

Main Menu

Converting a Real10 to string

Started by RuiLoureiro, April 28, 2013, 05:26:33 AM

Previous topic - Next topic

RuiLoureiro

Quote from: dedndave on May 14, 2013, 05:14:21 AM
if you look at my EvalReal function, i use a buffer that has 4 extra bytes at the beginning
i process numbers at Buffer+4
then, when i want to add a sign and a decimal point, i have room to work   :P
yes, it is usual. Unusual is to put behind, but in this case
               we dont need to change the starting address. We may work with
               indexes.

RuiLoureiro

Mikl__,

About accuracy
------------------

Suppose we have the number

            X=1.2345678912 3456 * 10^3

and my converter shows this:

        X=1.2345678012 * 10^3

It has only 7 correct digits

Now, suppose we did a lot of operations
and at the end we have this number:

            X=1.23456789123456 * 10^3

May i say the last digit 5 is correct ?
or
May i say the last digit 6 is correct ?

Mikl__

#17
qWord,
Great Thanks for the correction of errors in my programm!!!
RuiLoureiro,
I think that corrected other mistakes; masm windows console #
include \masm32\include\masm32rt.inc
.686
.mmx
.xmm

    Eprst proto lpReal10:ptr REAL10,lpDest:DWORD

.data
    _Real10_R REAL10 3.141592653589793238462E61; no crash
.code
main proc
LOCAL result[32]:BYTE

;    fldpi
;    fstp _Real10_R
    invoke Eprst,addr _Real10_R,ADDR result
    print ADDR result,13,10
   
    inkey " *** STOP - Eprst --- E N D ---*** "
    exit
   
main endp



    $max equ 60; <-- This number may be increased
    magic1 equ 4D10h;lg(2)*65536=19728,3...
    magic2  equ 35269h;log2(10)*65536=3,32192809488736234780*65536=217705,8796265381788254208..
.const
    cntr = -$max
    REPEAT 2*$max+1
        IF cntr NE 0
            REAL10 @CatStr(<1.0e>,%-cntr)
        ELSE
            tabs REAL10 1.0
        ENDIF
        WORD 0
        cntr = cntr + 1
    ENDM

    table0   label word
n=0
rept 100
dw (n mod 10 shl 8)+(n/10)+"00"
n=n+1
endm   
   
    table1 dd shift0,shift1,shift2,shift3,shift4
.code
Eprst proc uses edi esi ebx lpReal10:ptr REAL10,lpDest:DWORD
local iExp:dword
local x[3]:dword
local temp1:dword
local temp2:dword
    fninit
        mov ecx,lpReal10
    fld tbyte ptr [ecx]
    mov edi,lpDest
    mov ebx,[ecx]
    mov eax,[ecx+4]
    mov [x],ebx
    movzx edx,word ptr [ecx+8]
    mov [x+4],eax
    mov [x+8],edx
    cmp edx,8000h
    mov byte ptr [edi],'-'
    sbb esi,esi
    and esi,0Dh
    sub [edi],esi
    and edx,7FFFh
    jnz a2
Zero_Or_Denormal: cmp edx,eax
    jnz Denormal
        cmp ebx,eax
    jnz Denormal
    mov dword ptr [edi+1],'oreZ'
    mov dword ptr [edi+5],0
        ret
a2: cmp edx,7FFFh
    jz Infinity_Or_SNAN_Or_QNAN_Or_Uncertainty
Denormal:mov esi,10
    sub edx,16383
    mov word ptr [edi+21],'+E'
    imul edx,magic1
    and edx,0FFFF0000h
    sar edx,14
    mov iExp,edx
    jz @f
    cmp edx,4*$max
    jg a1
    cmp edx,-4*$max
    jge load
;------------------------------------------------
    dec edx
a1:neg edx
    sar edx,2
    mov temp1,edx
    imul edx,magic2
    sar edx,16
    mov temp2,edx
    fild temp2         ; get the characteristic
    fild temp1         ; log2(10)*expscale
    fldl2t    ; log2(10)
        fmul               ; log2(10)*expscale
        fsub st,st(1)      ; get only the mantissa but keep the characteristic
        f2xm1              ; 2^(mantissa)-1
        fld1
        fadd               ; add 1 and pop
        fscale
        fstp    st(1)      ; remove the characteristic
        jmp multiply
load: fld tabs[edx+edx*2]
multiply:fmul              ; X * 10^expscaleS
    fld st
    fstp tbyte ptr x
    xor edx,edx
@@: mov ecx,x+8
    mov ebx,x
        mov eax,x+4
    and ecx,7FFFh
    sub ecx,16382
cmp ecx,4
ja shift0
    jmp table1[ecx*4]
shift4::test eax,60000000h
    jz a6
    fld tabs[12]
    fmul
    add iExp,4
    fstp tbyte ptr x
    mov eax,x+4
        mov ebx,x
    shld edx,eax,1
    shld eax,ebx,1
    shl ebx,1
    add ebx,4
    jmp shift0
a6: shld edx,eax,4 ;ecx=1 ebx+4
    shld eax,ebx,4 ;ecx=2 ebx+8
    shl ebx,4      ;ecx=3 ebx+9
    add ebx,12     ;ecx=4 ebx+12
    jmp shift0
shift3::shld edx,eax,3
    shld eax,ebx,3
    shl ebx,3
    add ebx,9;10
    jmp shift0
shift2::shld edx,eax,2
    shld eax,ebx,2
    shl ebx,2
    add ebx,8
    jmp shift0
shift1::shld edx,eax,1
    shld eax,ebx,1
    shl ebx,1
    add ebx,4
shift0::adc eax,0
    adc edx,0
    mov [edi+1],dl
    mov byte ptr [edi+2],','
    or byte ptr [edi+1],'0'
   
    k=3
    REPEAT 17
        mul esi
        mov [edi+k],dl
        mov ecx,eax
        mov eax,ebx
        mul esi
        add ecx,edx
        adc byte ptr [edi+k],'0'
        mov ebx,eax
        mov eax,ecx
    k=k+1
    ENDM

    mul esi
    mov [edi+k],dl
    mov ecx,eax
    mov eax,ebx
    mul esi
    add ecx,edx
    adc byte ptr [edi+k],'0'
;--------------------------------------
    mov eax,iExp
    mov edx,eax
    sar eax,2
    sar edx,31
    mov ecx,esi
    xor eax,edx
    sub eax,edx
    and edx,2
    add byte ptr [edi+22],dl
    mov esi,eax
    mov edx,42949673;2^32/100
    mul edx
    mov eax,dword ptr table0[edx*2] ;edx = quotient of the division by 100
    mov dword ptr [edi+23],eax
    lea eax,[edx*4]
    shl edx,2
    lea edx,[edx+edx*2]
    lea edx,[eax+edx*8] ;edx = quotient*100
    sub esi,edx ;esi = remainder of the division by 100
    mov eax,dword ptr table0[esi*2]
    mov dword ptr [edi+25],eax
    mov dword ptr [edi+27],0
    ret
Infinity_Or_SNAN_Or_QNAN_Or_Uncertainty:
    cmp eax,80000000h
    jnz SNAN_Or_QNAN_Or_Uncertainty
    and ebx,ebx
    jnz SNAN_Or_QNAN_Or_Uncertainty
        mov dword ptr [edi+1],'ifnI'
        mov dword ptr [edi+5],'ytin'
        mov dword ptr [edi+9],0
    ret
SNAN_Or_QNAN_Or_Uncertainty:
    test eax,eax
    jns error
    test eax,40000000h
    jnz QNAN
        mov dword ptr [edi+1],'ngiS'
        mov dword ptr [edi+5],'N la'
        mov dword ptr [edi+9],'a no'
        mov dword ptr [edi+13],'muN '
        mov dword ptr [edi+17],'reb'
    ret
QNAN: test eax,3FFFFFFFh
    jnz @f
    test ebx,ebx
    jnz @f
        mov dword ptr [edi+1],'ecnU'
        mov dword ptr [edi+5],'iatr'
        mov dword ptr [edi+9],'ytn'
    ret
@@: mov dword ptr [edi+1],'eiuQ'
        mov dword ptr [edi+5],'oN t'
        mov dword ptr [edi+9],' a n'
        mov dword ptr [edi+13],'bmuN'
        mov dword ptr [edi+17],'re'
    ret
error: mov dword ptr [edi+1],'orrE'
        mov dword ptr [edi+5],'r'
    ret
Eprst endp
end main

RuiLoureiro

Hi Mikl__
          This is my first test using your Eprst procedure
          (in the second i got 1964)
          The first 7 results is only to test if procs
          are working correctly (but i have a single test
          procedure to each procedure)
          I will study your proc  :t
See the test file below. Test yourself and show us
the results
note: direct MN = 64bits Magic Number converter
Quote
3,141592653589793238E+0000   <---- Eprst
3.14159265358979324
3.14159265358979324
3.14159265358979324
3.14159265358979324
3.14159265358979324
3.14159265358979324
*** STOP - Converting PI ***

1399 cycles, ConvertFloat10ZX, _Real10_2

3296 cycles, ConvertFloat10, _Real10_2

1400 cycles, ConvertFloat10Z, _Real10_2

1780 cycles, ConvertFloat10DF, _Real10_2

1653 cycles, ConvertFloat10DR, _Real10_2

1054 cycles, ConvertFloat10BX, _Real10_2

1042 cycles, ConvertFloat10BF, _Real10_2

1038 cycles, ConvertFloat10BY, _Real10_2

1728 cycles, ConvertFloat10DY, _Real10_2

1702 cycles, ConvertFloat10DX, _Real10_2

1061 cycles, ConvertFloat10CT, _Real10_2

1772 cycles, ConvertFloat10DS, _Real10_2

3270 cycles, ConvertFloat10BW, _Real10_2

4045 cycles, ConvertFloat10DW, _Real10_2

1534 cycles, ConvertFloat10MR, _Real10_2

1794 cycles, ConvertFloat10DFD, _Real10_2

1697 cycles, ConvertFloat10DRD, _Real10_2

1059 cycles, ConvertFloat10BXD, _Real10_2

1057 cycles, ConvertFloat10BFD, _Real10_2

1052 cycles, ConvertFloat10BYD, _Real10_2

1850 cycles, ConvertFloat10DYD, _Real10_2

1755 cycles, ConvertFloat10DXD, _Real10_2

1078 cycles, ConvertFloat10CTD, _Real10_2

1772 cycles, ConvertFloat10DSD, _Real10_2

3378 cycles, ConvertFloat10BWD, _Real10_2

3942 cycles, ConvertFloat10DWD, _Real10_2

1775 cycles, ConvertReal10DF, _Real10_2

1656 cycles, ConvertReal10DR, _Real10_2

1061 cycles, ConvertReal10BX, _Real10_2

1041 cycles, ConvertReal10BF, _Real10_2

1041 cycles, ConvertReal10BY, _Real10_2

1724 cycles, ConvertReal10DY, _Real10_2

1699 cycles, ConvertReal10DX, _Real10_2

1075 cycles, ConvertReal10CT, _Real10_2

1768 cycles, ConvertReal10DS, _Real10_2

3271 cycles, ConvertReal10BW, _Real10_2

4041 cycles, ConvertReal10DW, _Real10_2

1807 cycles, ConvertReal10DFD, _Real10_2

1690 cycles, ConvertReal10DRD, _Real10_2

1066 cycles, ConvertReal10BXD, _Real10_2

1048 cycles, ConvertReal10BFD, _Real10_2

1053 cycles, ConvertReal10BYD, _Real10_2

1772 cycles, ConvertReal10DYD, _Real10_2

1762 cycles, ConvertReal10DXD, _Real10_2

1080 cycles, ConvertReal10CTD, _Real10_2

1810 cycles, ConvertReal10DSD, _Real10_2

4113 cycles, ConvertReal10BWD, _Real10_2

4461 cycles, ConvertReal10DWD, _Real10_2

1961 cycles, Eprst, _Real10_2                 <---- Eprst

*** Press any key to get the time table ***

***** Time table *****

Intel(R) Pentium(R) 4 CPU 3.40GHz (SSE3)

1038  cycles, ConvertFloat10BY, BCD, examine, fxtract, esp - 18 digits
1041  cycles, ConvertReal10BF, BCD, fxam, fxtract, esp - 18 digits
1041  cycles, ConvertReal10BY, BCD, examine, fxtract, esp - 18 digits
1042  cycles, ConvertFloat10BF, BCD, fxam, fxtract, esp - 18 digits
1048  cycles, ConvertReal10BFD, BCD, fxam, fxtract, esp - 18 digits
1052  cycles, ConvertFloat10BYD, BCD, examine, fxtract, esp - 18 digits
1053  cycles, ConvertReal10BYD, BCD, examine, fxtract, esp - 18 digits
1054  cycles, ConvertFloat10BX, BCD, fxam, fxtract, ebp - 18 digits
1057  cycles, ConvertFloat10BFD, BCD, fxam, fxtract, esp - 18 digits
1059  cycles, ConvertFloat10BXD, BCD, fxam, fxtract, ebp - 18 digits
1061  cycles, ConvertFloat10CT, BCD-CT, fxam, fxtract, esp - 18 digits
1061  cycles, ConvertReal10BX, BCD, fxam, fxtract, ebp - 18 digits
1066  cycles, ConvertReal10BXD, BCD, fxam, fxtract, ebp - 18 digits
1075  cycles, ConvertReal10CT, BCD-CT, fxam, fxtract, esp - 18 digits
1078  cycles, ConvertFloat10CTD, BCD-CT, fxam, fxtract, esp - 18 digits
1080  cycles, ConvertReal10CTD, BCD-CT, fxam, fxtract, esp - 18 digits
1399  cycles, ConvertFloat10ZX, BCD - old - 18 digits
1400  cycles, ConvertFloat10Z, BCD -old - 18 digits
1534  cycles, ConvertFloat10MR, direct MN, examine, fxtract, ebp - 18 digits
1653  cycles, ConvertFloat10DR, direct, examine, fxtract, ebp - 18 digits
1656  cycles, ConvertReal10DR, direct, examine, fxtract, ebp - 18 digits
1690  cycles, ConvertReal10DRD, direct, examine, fxtract, ebp - 18 digits
1697  cycles, ConvertFloat10DRD, direct, examine, fxtract, ebp - 18 digits
1699  cycles, ConvertReal10DX, direct, fxam, fxtract, esp - 18 digits
1702  cycles, ConvertFloat10DX, direct, fxam, fxtract, esp - 18 digits
1724  cycles, ConvertReal10DY, direct, examine, fxtract, esp - 18 digits
1728  cycles, ConvertFloat10DY, direct, examine, fxtract, esp - 18 digits
1755  cycles, ConvertFloat10DXD, direct, fxam, fxtract, esp - 18 digits
1762  cycles, ConvertReal10DXD, direct, fxam, fxtract, esp - 18 digits
1768  cycles, ConvertReal10DS, direct, fxam, fyl2x, ebp - 18 digits
1772  cycles, ConvertFloat10DSD, direct, fxam, fyl2x, ebp - 18 digits
1772  cycles, ConvertReal10DYD, direct, examine, fxtract, esp - 18 digits
1772  cycles, ConvertFloat10DS, direct, fxam, fyl2x, ebp - 18 digits
1775  cycles, ConvertReal10DF, direct, examine, fyl2x, ebp - 18 digits
1780  cycles, ConvertFloat10DF, direct, examine, fyl2x, ebp - 18 digits
1794  cycles, ConvertFloat10DFD, direct, examine, fyl2x, ebp - 18 digits
1807  cycles, ConvertReal10DFD, direct, examine, fyl2x, ebp - 18 digits
1810  cycles, ConvertReal10DSD, direct, fxam, fyl2x, ebp - 18 digits
1850  cycles, ConvertFloat10DYD, direct, examine, fxtract, esp - 18 digits
1961  cycles, Eprst, -18 digits
3270  cycles, ConvertFloat10BW, BCD, Save FPU, fxam, fxtract, ebp - 18 digits
3271  cycles, ConvertReal10BW, BCD, Save FPU, fxam, fxtract, ebp - 18 digits
3296  cycles, ConvertFloat10, BCD, Save FPU -old - 18 digits
3378  cycles, ConvertFloat10BWD, BCD, Save FPU, fxam, fxtract, ebp - 18 digits
3942  cycles, ConvertFloat10DWD, direct,Save FPU, fxam, fxtract, esp -18 digits
4041  cycles, ConvertReal10DW, direct,Save FPU, fxam, fxtract, esp -18 digits
4045  cycles, ConvertFloat10DW, direct,Save FPU, fxam, fxtract, esp -18 digits
4113  cycles, ConvertReal10BWD, BCD, Save FPU, fxam, fxtract, ebp - 18 digits
4461  cycles, ConvertReal10DWD, direct,Save FPU, fxam, fxtract, esp -18 digits
********** END **********

All procedures use _Real10_2 for test

Quote
;-------- for timing -------------
_Real10_2      dt -1234.5678E+234

            ...

         START_COUNTER_CYCLE_HIGH_PRIORITY_CLASS
         invoke  ConvertReal10DWD, addr _Real10_2, 0, $DECIMALPLACES_REAL10
         SAVE_COUNTER_CYCLE < cycles, ConvertReal10DWD, _Real10_2 >

         START_COUNTER_CYCLE_HIGH_PRIORITY_CLASS
         invoke Eprst,addr _Real10_2, addr _RclBuf
         SAVE_COUNTER_CYCLE < cycles, Eprst, _Real10_2 >

RuiLoureiro

Now for 19 digits - (no BCD)

_Real10_R = -12345678.12345678

we have:
note 1: Float uses length; Real only null terminated string

note 2: your converter shows only in scientific format
        and all my converters in 3 formats: integer, decimal, scientific
   
Quote
-1,234567812345678000E+0007
-12345678.12345678
-12345678.12345678
-12345678.12345678
-12345678.12345678
-12345678.12345678
-12345678.12345678
-12345678.12345678
*** STOP - Converting - 19 digits ***

1623 cycles, ConvertFloat10DF, _Real10_R

1481 cycles, ConvertFloat10DR, _Real10_R

1492 cycles, ConvertFloat10DY, _Real10_R

1484 cycles, ConvertFloat10DX, _Real10_R

1630 cycles, ConvertFloat10DS, _Real10_R

3919 cycles, ConvertFloat10DW, _Real10_R

1304 cycles, ConvertFloat10MR, _Real10_R

1609 cycles, ConvertFloat10DFD, _Real10_R

1481 cycles, ConvertFloat10DRD, _Real10_R

1606 cycles, ConvertFloat10DYD, _Real10_R

1591 cycles, ConvertFloat10DXD, _Real10_R

1622 cycles, ConvertFloat10DSD, _Real10_R

3819 cycles, ConvertFloat10DWD, _Real10_R

1596 cycles, ConvertReal10DF, _Real10_R

1486 cycles, ConvertReal10DR, _Real10_R

1499 cycles, ConvertReal10DY, _Real10_R

1478 cycles, ConvertReal10DX, _Real10_R

1644 cycles, ConvertReal10DS, _Real10_R

3930 cycles, ConvertReal10DW, _Real10_R

1601 cycles, ConvertReal10DFD, _Real10_R

1481 cycles, ConvertReal10DRD, _Real10_R

1553 cycles, ConvertReal10DYD, _Real10_R

1560 cycles, ConvertReal10DXD, _Real10_R

1642 cycles, ConvertReal10DSD, _Real10_R

3808 cycles, ConvertReal10DWD, _Real10_R

1780 cycles, Eprst, _Real10_R

*** Press any key to get the time table ***

***** Time table *****

Intel(R) Pentium(R) 4 CPU 3.40GHz (SSE3)

1304  cycles, ConvertFloat10MR, direct MN, examine, fxtract, ebp - 19 digits
1478  cycles, ConvertReal10DX, direct, fxam, fxtract, esp - 19 digits
1481  cycles, ConvertFloat10DRD, direct, examine, fxtract, ebp - 19 digits
1481  cycles, ConvertReal10DRD, direct, examine, fxtract, ebp - 19 digits
1481  cycles, ConvertFloat10DR, direct, examine, fxtract, ebp - 19 digits
1484  cycles, ConvertFloat10DX, direct, fxam, fxtract, esp - 19 digits
1486  cycles, ConvertReal10DR, direct, examine, fxtract, ebp - 19 digits
1492  cycles, ConvertFloat10DY, direct, examine, fxtract, esp - 19 digits
1499  cycles, ConvertReal10DY, direct, examine, fxtract, esp - 19 digits
1553  cycles, ConvertReal10DYD, direct, examine, fxtract, esp - 19 digits
1560  cycles, ConvertReal10DXD, direct, fxam, fxtract, esp - 19 digits
1591  cycles, ConvertFloat10DXD, direct, fxam, fxtract, esp - 19 digits
1596  cycles, ConvertReal10DF, direct, examine, fyl2x, ebp - 19 digits
1601  cycles, ConvertReal10DFD, direct, examine, fyl2x, ebp - 19 digits
1606  cycles, ConvertFloat10DYD, direct, examine, fxtract, esp - 19 digits
1609  cycles, ConvertFloat10DFD, direct, examine, fyl2x, ebp - 19 digits
1622  cycles, ConvertFloat10DSD, direct, fxam, fyl2x, ebp - 19 digits
1623  cycles, ConvertFloat10DF, direct, examine, fyl2x, ebp - 19 digits
1630  cycles, ConvertFloat10DS, direct, fxam, fyl2x, ebp - 19 digits
1642  cycles, ConvertReal10DSD, direct, fxam, fyl2x, ebp - 19 digits
1644  cycles, ConvertReal10DS, direct, fxam, fyl2x, ebp - 19 digits
1780  cycles, Eprst, -19 digits
3808  cycles, ConvertReal10DWD, direct,Save FPU, fxam, fxtract, esp -19 digits
3819  cycles, ConvertFloat10DWD, direct,Save FPU, fxam, fxtract, esp -19 digits
3919  cycles, ConvertFloat10DW, direct,Save FPU, fxam, fxtract, esp -19 digits
3930  cycles, ConvertReal10DW, direct,Save FPU, fxam, fxtract, esp -19 digits
********** END **********

jj2007

Quote from: RuiLoureiro on May 15, 2013, 02:16:34 AM
Now for 19 digits - (no BCD)

_Real10_R = -12345678.12345678

That is 16 digits - a bit more is possible:
include \masm32\MasmBasic\MasmBasic.inc        ; download
        Init
        fld FP10(123456789.123456789123)
        Inkey Str$("Result=%Jf", ST(0))
        Exit
end start

Result=123456789.1234567891

RuiLoureiro

Quote from: jj2007 on May 15, 2013, 02:31:51 AM
Quote from: RuiLoureiro on May 15, 2013, 02:16:34 AM
Now for 19 digits - (no BCD)

_Real10_R = -12345678.12345678

That is 16 digits - a bit more is possible:
But you need to understand first what it means
             unless you want to say that all numbers have 19 digits (to show)!   :P

Quote
Suppose we have the number

            X=1.2345678912 3456 * 10^3

If we want dp=10 decimal places, it means that we need to
move the decimal point 10 places right (btw 2 and 3).

To get the integer with dp+1 digits we need to remove
the factor 10^3

            Y= X * 10^-3    (exponent removed, Y=1.2345678912 3456)

Now to get the integer we need to multiply by 10^dp

            Z= Y * 10^dp = X * 10^-3 * 10^dp
           
             = X* 10^(dp-exponent)   (exponent = 3)

Now, calling
                expsacale= dp-exponent

we need to do this:

                Z = X * 10^expscale

If dp=10 than
                Z= 12345678912 . 3456

Now, if this number is inside st(0) we do

        fistp    qword ptr _QwordVar

and we get
            _QwordVar = 12345678912   (and we know exponent=+3)


So, to convert to string we do this

            _string ="1.2345678912" plus "e+3"

and we show the number with 10 decimal places.

RuiLoureiro

Mikl__,
           Some data you need to see

Quote
;            From Eprst we get this:
;
; 3,141592653589793238E+0000
;0000_80000000_00000000 = 3,36210314311209 2086E-4932
;0000_FFFFFFFF_FFFFFFFF = 6,72420628622418 4172E-4932

;0000_00000000_00000001 = 0,840525785778023021E-4932   <--- ??? x
;0000_FFFFFFFF_FFFFFFFF = 3,362103143112092086E-4932   <--- ??? y
;7FFF_80000000_00000000 = Infinity
;FFFF_80000000_00000000 =-Infinity
;7FFE_FFFFFFFF_FFFFFFFF = 1,18973149535723176 4E+4932
;FFFE_FFFFFFFF_FFFFFFFF =-1,18973149535723176 4E+4932
; *** STOP - Eprst  end test digits ***
;
; from DAVE evaluator prog:
;
;0000_80000000_00000000: +3.36210314311209 350626e-4932 (p)
;0000_FFFFFFFF_FFFFFFFF: +6.72420628622418 701216e-4932 (p)

;0000_00000000_00000001: +3.64519953188247460253e-4951 (d)  <--- x
;0000_FFFFFFFF_FFFFFFFF: +6.72420628622418701216e-4932 (p)  <--- y
;7FFF_80000000_00000000: +8
;FFFF_80000000_00000000: -8
;7FFE_FFFFFFFF_FFFFFFFF: +1.18973149535723176 502e+4932
;FFFE_FFFFFFFF_FFFFFFFF: -1.18973149535723176 502e+4932
;
; From BX
; -------
;0000_80000000_00000000 = 3.36210314311209 35e-4932
;0000_FFFFFFFF_FFFFFFFF = 6.72420628622418 70e-4932
;7FFE_FFFFFFFF_FFFFFFFF = 1.18973149535723177e+4932
;FFFE_FFFFFFFF_FFFFFFFF =-1.18973149535723177e+4932
; *** STOP - ConvertFloat10BX  end test digits ***

dedndave

hi Rui   :biggrin:

to make the infinity symbol (lemniscate), hold the Alt key, then 236 on the 10-key pad, then release the Alt key

RuiLoureiro

hi dave,
             ok, give me your keyboard, please   ( ý <- Alt+236  :P )

Mikl,
This is your prog.
See it.

What do you do if exponent > 4932 ?
i get 10^4933 = infinity.

Quote
local temp1:dword
local temp2:dword

    fninit
    mov ecx,lpReal10
    fld tbyte ptr [ecx]
    mov edi,lpDest
    mov ebx,[ecx]
    mov eax,[ecx+4]
    mov
  • ,ebx
        movzx edx,word ptr [ecx+8]
        mov [x+4],eax
        mov [x+8],edx
        cmp edx,8000h                  <---- ???
        mov byte ptr [edi],'-'
        sbb esi,esi
        and esi,0Dh
        sub [edi],esi
        and edx,7FFFh
        jnz a2
       
    Zero_Or_Denormal: cmp edx,eax
                      jnz Denormal
                      cmp ebx,eax
                      jnz Denormal
                      mov dword ptr [edi+1],'oreZ'
                      mov dword ptr [edi+5],0
                      ret

                a2:   cmp edx,7FFFh
                      jz Infinity_Or_SNAN_Or_QNAN_Or_Uncertainty
       
    Denormal:   mov     esi,10              ; <----- is Denormal or Normal ?   
                sub     edx,16383
                mov     word ptr [edi+21],'+E'
                imul    edx,magic1
                and     edx,0FFFF0000h
                sar     edx,14
                mov     iExp,edx
                jz      @f
                cmp     edx,4*$max
                jg      a1
                cmp     edx,-4*$max
                jge     load
    ;------------------------------------------------
                dec edx
            a1: neg edx
                sar edx,2
                mov temp1,edx
                imul edx,magic2
                sar edx,16
                mov temp2,edx
                fild temp2
                fild temp1
                fldl2t
                fmul
                fsub st,st(1)
                f2xm1
                fld
                fadd       
                fscale
                fstp    st(1)
                jmp     multiply
               
        load:   fld     tabs[edx+edx*2]
       
       multiply:fmul
                fld     st
                fstp    tbyte ptr x    ; --- a new real10 number again ---

dedndave

maybe i should use +Infinity and -Infinity, rather than the lemniscate char   :(

Mikl__

mov ecx,lpReal10
    fld tbyte ptr [ecx] <-- load in FPU REAL10
    mov ebx,[ecx] <-- in EBX 0-31 bits
    mov eax,[ecx+4] <-- in EAX 32-63 bits   
    movzx edx,word ptr [ecx+8] <-- in EDX 79-64 bits and 95-80 bits are zeros
    cmp edx,8000h    <---- compare number is negatve or positive
    mov byte ptr [edi],'-' <-- ASCII-code "minus"=2Dh
    sbb esi,esi <-- if number is negatve ESI=0 if nubmer is positive ESI=FFFFFFFF
    and esi,0Dh <-- if number is negatve ESI=0 if nubmer is positive ESI=0Dh
    sub [edi],esi <-- if number is negatve [EDI]=2Dh="-" if nubmer is positive [EDI]=2D-0D=20h=" "
    and edx,7FFFh <-- equal fabs REAL10

Mikl__

#27
Quote; from DAVE evaluator prog:
;7FFF_80000000_00000000: +8 +∞ ?
;FFFF_80000000_00000000: -8
from IEEE754
Encodings of ±2k+1-N n into Binary Fields :
|Number Type| Sign Bit| K+1 bit Exponent| Nth bit |N-1 bits of Significand
|Infinities: |binary 111...111 |1| 0
and from Intel® 64 and IA-32 Architectures Software Developer's Manual
Volume 1: Basic Architecture
Table 8-3. Unsupported Double Extended-Precision Floating-Point Encodings and
Pseudo-Denormals
|Class|Sign|Biased Exponent|Integer|Fraction
|Positive Pseudo-infinity|0|11..11|0|00..00
|Negative Pseudo-infinity|1|11..11|0|00..00
|||← 15 bits →||← 63 bits →
Numerical Computation Guide. November 2005
Table 3-12 IEEE Values: Double Exterded Precision (x86)

|Common Name|Bit Patern (x86 Architecture)|Value
|+∞|7FFF 80000000 00000000|+∞
|-∞|FFFF 80000000 00000000|-∞
|min positive subnormal|0000 00000000 00000001|1.82259976594123730126E-4951
|max positive normal |7FFE FFFFFFFF FFFFFFFF |1.18973149535723176505e+4932
|min positive normal |0001 80000000 00000000 |3.36210314311209350626e−4932
|max positive subnormal |0000 7FFFFFFF FFFFFFFF |3.36210314311209350608e−4932
|quiet NaN with greatest fraction| 7FFF FFFFFFFF FFFFFFFF |QNaN
|quiet NaN with least fraction| 7FFF C0000000 00000000 |QNaN
|signaling NaN with greatest fraction| 7FFF BFFFFFFF FFFFFFFF |SNaN
|signaling NaN with least fraction| 7FFF 80000000 00000001 |SNaN

Mikl__

Hi, dedndave!
Quotefrom DAVE evaluator prog:
About what kind of program said RuiLoureiro?

2.99GHz 3.49Gb RAM Pentium 4 (Eprst.zip)
465 MHz, 256 Mb RAM Celeron (02.zip)

dedndave

you can download it here (Evr1.zip)

http://masm32.com/board/index.php?topic=222.0

C:\Masm32\Asm32\EvalReal => evr
Evr: Ling Long Kai Fang Real Number Evaluation Utility
DednDave  5-2013  Ver 1.0

  This program evaluates hexadecimal Intel real numbers from the command line.
     The characters 0-9, A-F, P, X, and S are read, all others are ignored.
  This allows the use of spaces, underscores, etc, to separate the hex digits.
If the number of hex digits doesn't total 8, 16, or 20, this message is shown.
           The P switch may be used to show values at full Precision.
   The X switch may be used to show values with 3 eXtra digits of precision.
                      The X switch overrides the P switch.
      The S switch may be used to Step the LSB, showing 3 adjacent values.
               (d) = Denormal               (p) = Pseudo-Denormal

                    Example: Evr 4000 C90F DAA2 2168 C235 xs