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 string to real4

Started by RuiLoureiro, April 15, 2013, 04:35:25 AM

Previous topic - Next topic

RuiLoureiro

    Hi all,

    . Sometimes some friends here ask me where is the
      ASM file.
(Hi Dave ! Hi qWord !)
     
    . Well, in this post i give ConvertString4D.inc
      which contains the ASM ConvertString4D procedure,
      constants and macros, and a text file Converter4.txt
      where i explain something about that. (See Converter4.zip below)

    . ConvertString4D procedure is a proc that converts
      a null terminated string into a real4 dword variable.
      The string may be written like this one:

         "-123.4567E-1"  or the same as "  - 000 1 2 3  . 45 67 E - 0001"

      It takes 119 cycles more or less in my P4.
            (qWord, in your i7 119 may give 40, no ?)

    . TestCnvDD9.exe shows conversions of 10 strings
      by all converters
     
    . Please, could you run TestCnvDD10.exe
      and show the results here ?
      Thanks
      Rui

NOTE: ConvertString4Y0 doesnt convert a string like this:
           "- 123" or "-001236789" or "-1.234 E5" (spaces and more than 8 integers)

    About each converter
    --------------------

                    load   stack   intermediate    save    conversion
                           access    buffer     FPU & CPU    method       obs.
------------------------------------------------------------------------------
1  ConvertString4BZ 1 byte   ebp        yes          no         BCD       (1,3)       

2  ConvertString4BX 1 byte   ebp        yes          yes        BCD       (1,3)

3  ConvertString4BY 1 byte   esp        yes          no         BCD       (1,3)

4  ConvertString4B  1 byte   esp        yes          yes        BCD       (1,3)

5  ConvertString4BW 1 byte   ebp         no          no         BCD       (1,3)

6  ConvertString4BF 1 byte   esp         no          no         BCD       (1,3)
-------------------------------------------------------------------------------
7  ConvertString4Y0 1 byte   ebp         no          no        direct     (1)

8  ConvertString4Y  1 byte   ebp         no          no        direct     (2)

9  ConvertString4YM 1 byte   ebp         no          no        direct     (2)

10 ConvertString4YF 1 byte   esp         no          no        direct     (2)
--------------------------------------------------------------------------------
11 ConvertString4T  1 byte   ebp         yes         no        xlatb      (2)

12 ConvertString4TX 1  "     esp         yes         no        xlatb      (2)

13 ConvertString4TY 1 byte   esp         yes         no       code table  (2)

14 ConvertString4TW 1  "     esp         yes         no           "       (2) 

15 ConvertString4T4 4  "     esp         yes         no           "       (2)
--------------------------------------------------------------------------------
16 ConvertString4D  1  "     ebp          no         no        direct     (2)

17 ConvertString4DS 1  "     ebp          no         yes       direct     (2)   
---------------------------------------------------------------------------------
obs. (1) no spaces/no zeroes
     (2) remove spaces/zeroes
     (3) rcl strings sampled from right to left
     (4) all use tables of qwords to get the power of 10: 10^n or 10^-n


file: TestCnvDD9.exe

It is to show the results in P4 XP sp3
converting 10 different strings
--------------------------------------

ConvertString4TW
1234.567

ConvertString4T4
1234.567

ConvertString4D
1234.567

ConvertString4DS
1234.567

*** STOP RclStr04 +1234.567 ***
converting _RclStr05 +1234E+12

ConvertString4B
1.2339999E+15

ConvertString4BX
1.2339999E+15

ConvertString4BZ
1.2339999E+15

ConvertString4BY
1.2339999E+15

ConvertString4BW
1.2339999E+15

ConvertString4BF
1.2339999E+15

ConvertString4Y0
1.2339999E+15

ConvertString4Y
1.2339999E+15

ConvertString4YM
1.2339999E+15

ConvertString4YF
1.2339999E+15

ConvertString4T
1.2339999E+15

ConvertString4TX
1.2339999E+15

ConvertString4TY
1.2339999E+15

ConvertString4TW
1.2339999E+15

ConvertString4T4
1.2339999E+15

ConvertString4D
1.2339999E+15

ConvertString4DS
1.2339999E+15

*** STOP RclStr05 +1234E+12 ***
converting _RclStr06 .567E+12

ConvertString4B
1 ERROR eax
ConvertString4BX
1 ERROR eax
ConvertString4BZ
1 ERROR eax
ConvertString4BY
1 ERROR eax
ConvertString4BW
1 ERROR eax
ConvertString4BF
1 ERROR eax
ConvertString4Y0
5.6699997E+11

ConvertString4Y
5.6699997E+11

ConvertString4YM
5.6699997E+11

ConvertString4YF
5.6699997E+11

ConvertString4T
5.6699997E+11

ConvertString4TX
5.6699997E+11

ConvertString4TY
5.6699997E+11

ConvertString4TW
5.6699997E+11

ConvertString4T4
5.6699997E+11

ConvertString4D
5.6699997E+11

ConvertString4DS
5.6699997E+11

*** STOP RclStr06 .567E+12 ***
converting _RclStr07 +1234.567E+12

ConvertString4B
1.234567E+15

ConvertString4BX
1.234567E+15

ConvertString4BZ
1.234567E+15

ConvertString4BY
1.234567E+15

ConvertString4BW
1.234567E+15

ConvertString4BF
1.234567E+15

ConvertString4Y0
1.234567E+15

ConvertString4Y
1.234567E+15

ConvertString4YM
1.234567E+15

ConvertString4YF
1.234567E+15

ConvertString4T
1.234567E+15

ConvertString4TX
1.234567E+15

ConvertString4TY
1.234567E+15

ConvertString4TW
1.234567E+15

ConvertString4T4
1.234567E+15

ConvertString4D
1.234567E+15

ConvertString4DS
1.234567E+15

*** STOP RclStr07 +1234.567E+12 ***
converting _RclStr08 +000000 012 34.56 7 E + 000012

ConvertString4B
3 ERROR eax
ConvertString4BX
3 ERROR eax
ConvertString4BZ
3 ERROR eax
ConvertString4BY
3 ERROR eax
ConvertString4BW
3 ERROR eax
ConvertString4BF
1 ERROR eax
ConvertString4Y0
1 ERROR eax
ConvertString4Y
1.234567E+15

ConvertString4YM
1.234567E+15

ConvertString4YF
1.234567E+15

ConvertString4T
1.234567E+15

ConvertString4TX
1.234567E+15

ConvertString4TY
1.234567E+15

ConvertString4TW
1.234567E+15

ConvertString4T4
1.234567E+15

ConvertString4D
1.234567E+15

ConvertString4DS
1.234567E+15

*** STOP RclStr08 +000000 012 34.56 7 E + 000012 ***
converting _RclStr09 +1.234E+45

ConvertString4B
8 ERROR eax
ConvertString4BX
8 ERROR eax
ConvertString4BZ
8 ERROR eax
ConvertString4BY
8 ERROR eax
ConvertString4BW
8 ERROR eax
ConvertString4BF
8 ERROR eax
ConvertString4Y0
8 ERROR eax
ConvertString4Y
8 ERROR eax
ConvertString4YM
8 ERROR eax
ConvertString4YF
8 ERROR eax
ConvertString4T
8 ERROR eax
ConvertString4TX
8 ERROR eax
ConvertString4TY
8 ERROR eax
ConvertString4TW
8 ERROR eax
ConvertString4T4
8 ERROR eax
ConvertString4D
8 ERROR eax
ConvertString4DS
8 ERROR eax
*** STOP RclStr09 +1.234E+45 ***
converting _RclStr10 +1.234E-45

ConvertString4B
8 ERROR eax
ConvertString4BX
8 ERROR eax
ConvertString4BZ
8 ERROR eax
ConvertString4BY
8 ERROR eax
ConvertString4BW
8 ERROR eax
ConvertString4BF
8 ERROR eax
ConvertString4Y0
7 ERROR eax
ConvertString4Y
1.4012985E-45

ConvertString4YM
1.4012985E-45

ConvertString4YF
1.4012985E-45

ConvertString4T
1.4012985E-45

ConvertString4TX
1.4012985E-45

ConvertString4TY
1.4012985E-45

ConvertString4TW
1.4012985E-45

ConvertString4T4
1.4012985E-45

ConvertString4D
1.4012985E-45

ConvertString4DS
1.4012985E-45

*** STOP RclStr10 +1.234E-45 and END ***



file: TestCnvDD10.exe

My results in P4 XP sp3
-----------------------
Quote
converting _RclStr04 +1234.567

2665 cycles, ConvertString4, _RclStr04

2642 cycles, ConvertString4BX, _RclStr04

566 cycles, ConvertString4BZ, _RclStr04

528 cycles, ConvertString4BY, _RclStr04

452 cycles, ConvertString4BW, _RclStr04

455 cycles, ConvertString4BF, _RclStr04

107 cycles, ConvertString4Y0, _RclStr04

127 cycles, ConvertString4Y, _RclStr04

138 cycles, ConvertString4YM, _RclStr04

122 cycles, ConvertString4YF, _RclStr04

231 cycles, ConvertString4T, _RclStr04

177 cycles, ConvertString4TX, _RclStr04

169 cycles, ConvertString4TY, _RclStr04

151 cycles, ConvertString4TW, _RclStr04

211 cycles, ConvertString4T4, _RclStr04

119 cycles, ConvertString4D, _RclStr04

2218 cycles, ConvertString4DS, _RclStr04

*** STOP and END ***

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

107  cycles, ConvertString4Y0, direct - no spaces, no zeroes
119  cycles, ConvertString4D, direct
122  cycles, ConvertString4YF, direct
127  cycles, ConvertString4Y, direct
138  cycles, ConvertString4YM, direct
151  cycles, ConvertString4TW, code table
169  cycles, ConvertString4TY, code table
177  cycles, ConvertString4TX, xlatb
211  cycles, ConvertString4T4, code table
231  cycles, ConvertString4T, xlatb
452  cycles, ConvertString4BW, BCD
455  cycles, ConvertString4BF, BCD
528  cycles, ConvertString4BY, BCD
566  cycles, ConvertString4BZ, BCD
2218  cycles, ConvertString4DS, direct, save FPU
2642  cycles, ConvertString4BX, BCD, save FPU
2665  cycles, ConvertString4B, BCD, save FPU
********** END **********

Gunther

Hi RuiLoureiro

here are my results with an i7 (Windows 64 bit):

Quote
converting _RclStr04 +1234.567

677 cycles, ConvertString4, _RclStr04

636 cycles, ConvertString4BX, _RclStr04

208 cycles, ConvertString4BZ, _RclStr04

198 cycles, ConvertString4BY, _RclStr04

195 cycles, ConvertString4BW, _RclStr04

182 cycles, ConvertString4BF, _RclStr04

44 cycles, ConvertString4Y0, _RclStr04

50 cycles, ConvertString4Y, _RclStr04

46 cycles, ConvertString4YM, _RclStr04

51 cycles, ConvertString4YF, _RclStr04

84 cycles, ConvertString4T, _RclStr04

66 cycles, ConvertString4TX, _RclStr04

57 cycles, ConvertString4TY, _RclStr04

62 cycles, ConvertString4TW, _RclStr04

67 cycles, ConvertString4T4, _RclStr04

49 cycles, ConvertString4D, _RclStr04

483 cycles, ConvertString4DS, _RclStr04

*** STOP and END ***

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

44  cycles, ConvertString4Y0, direct - no spaces, no zeroes
46  cycles, ConvertString4YM, direct
49  cycles, ConvertString4D, direct
50  cycles, ConvertString4Y, direct
51  cycles, ConvertString4YF, direct
57  cycles, ConvertString4TY, code table
62  cycles, ConvertString4TW, code table
66  cycles, ConvertString4TX, xlatb
67  cycles, ConvertString4T4, code table
84  cycles, ConvertString4T, xlatb
182  cycles, ConvertString4BF, BCD
195  cycles, ConvertString4BW, BCD
198  cycles, ConvertString4BY, BCD
208  cycles, ConvertString4BZ, BCD
483  cycles, ConvertString4D, direct, save FPU
636  cycles, ConvertString4BX, BCD, save FPU
677  cycles, ConvertString4B, BCD, save FPU
********** END **********

Gunther
You have to know the facts before you can distort them.

RuiLoureiro

Hi Gunther
                   Thanks !  :icon14:

----------------------------------------------------
Converting from string to real4 using FPU
----------------------------------------------------

    We know it is an old story that many of us know well.
    Nevertheless, there are people that want to try to write
    his own converter or they are trying to learn.
    For this reason, i will try to remember some basic concepts
    based on a general example, to be simple. This is just to
    answer some questions like «why you do this ?»,
    «why you do that ?» ...

Quote
       ----------------       
    A. introduction
       ----------------

        If our string is defined as _string db "-1234.567E+12",0
                                 or _string db "-1234.567e+12",0

        In general, we have only the symbols: '0' to '9', '+', '-', '.', 'E' and 'e'

        In general, we have 3 parts:

                    1. integer  part: -1234 ( from starting point to '.' )
                    2. decimal  part:  567  ( after '.' to 'E'           )
                    3. exponent part: +12   ( after 'E' to 0             )

        This -1234.567E+12  means this:  -1234.567 * 10^+12
       
        But    -1234.567 = -(1234 + 0.567)
         
        or               =  -1234 - 0.567  = -1234 - 567 * 10^-3
       
                         = (-1234) + (-567) * (10^-3)  (to use + instead of -)
       
             ( 0.567 = 567 * 10^-3      where 3 is the number of decimal places = ndd ).

        note: if we have an expression 10^-n, then -n means «go backward n digits»
              if we have an expression 10^+n, then +n means «go forward  n digits»


        Finally, we have the complete expression

        -1234.567E+12= -1234.567 * 10^+12 = [(-1234) + (-567 * 10^-4)] * 10^+12

                                          =  (ecx + edi * 10^-ebx) * 10^edx
        where:
                ecx = integer part
                edi = decimal part (has the same sign as the integer part)
                ebx = number of decimal places (is allways a positive value)
                edx = exponent

       -------------------------------------------------------
    B. floating point notation or scientific notation
       -------------------------------------------------------

       siiiiii.dddddddEsxxxx      where s = sign +/-         e or E = 10^ factor
                                        i = integer  digit
                                        d = decimal  digit
                                        x = exponent digit

       means or stands for:  siiiiii.ddddddd * 10^sxxxx  (well, 's' is one 's' not the same!)

       we have 3 things:
                            1. integer  part = siiiiii
                            2. decimal  part = sddddddd  (the sign is implied)
                            3  exponent part = sxxxx    => power part = 10^sxxxx


        all different cases
        ----------------------

        case 1:   1234       -> start with integer
       
        case 2:   .567       -> start with decimal (point)

        case 3:   E+12       -> start with power. this case should be error
                                because e+10 may be 2.718281828459045+10=12.718281828459045
                                and not scientific notation

        case 4: 1234.567     -> integer plus decimal

        case 5: 1234E+12     -> integer plus power

        case 6: .567E+12     -> decimal plus power

        case 7: 1234.567E+12 -> integer plus decimal plus power

        other cases: 1.234E+45 or 1.234E-45  (overflow/underflow)
       
       ------------------------------
    C.    spaces or not spaces
       ------------------------------

        Is there another meaning for -123.45 6782 than the same as -123.456782 ?
        or
        Is there another meaning for -1 23.45 67 82 than the same as -123.456782 ?

        I like to write with spaces and i dont like to get error from a converter
        if i use spaces. The converter should remove it.


       --------------------------------------
    D.   one idea to parse the string
       --------------------------------------

        note: if we want to use FPU, we should define 3 local variables
              For instance, integerDD, decimalDD, exponentDD (all dwords)
              because we cannot pass values in registers to FPU

        1. find the sign (and save it if it is negative)
       
        2. a) IntegerPart
              -----------------
             
              a1) get the character to AL and subtract 30h

              . If carry set, we have 3/4 cases: 
                                               . -2  is '.'  -> go to DecimalPart
                                               . -16 is space  (if we want)
                                               . -48 is 0    => endinteger
                                               . unacceptable character
              . cmp al, 9
                jbe isdigit     -> save it or do what you want


              .  now, it must be:
                                . 21 is 'E'     -> go to ExponentPart
                                . 53 is 'e'
                                . unacceptable character

           b) DecimalPart
              ----------------

              b1) get the character to AL and subtract 30h

              . If carry set, we have 2/3 cases: 
                                               . -16 is space  (if we want)
                                               . -48 is 0    => enddecimal
                                               . unacceptable character
              . cmp al, 9
                jbe isdigit     -> save it or do what you want


              .  now, it must be:
                                . 21 is 'E'     -> go to ExponentPart
                                . 53 is 'e'
                                . unacceptable character

           c) ExponentPart
              ------------------

              c1) find the sign (and save it if it is negative)
             
              c2) get the character to AL and subtract 30h

              . If carry set, we have 2/3 cases: 
                                               . -16 is space  (if we want)
                                               . -48 is 0    => endexponent
                                               . unacceptable character
              . cmp al, 9
                jbe isdigit     -> save it or do what you want


              .  now it must be:
                                . unacceptable character
           

        endinteger: we must have at least 1 integer or integer = 0 or error
        ----------
         
        enddecimal: we must have at least 1 integer or integer = 0 or error
        ----------
       
        endexponent: we must have at least 1 integer or 1 decimal or error       
        -----------               (.E should be error)
                     neg the value if negative


        3. now, we have the values of each part in integerDD, decimalDD, exponentDD

            3.1 change the sign of integerDD and decimalDD if there is sign
           
            3.2 load the values into FPU and compute the expression

                      fild    integerDD                   
                      fild    decimalDD
                     
                      multiply by 10^-ndd (ndd=number of decimal digits)

                      multiply by 10^exponentDD

        4. store the result
           (and test if there is an error if you want. The result may be infinity!)

       -----------------------------------------
    D1. one solution to remove spaces
       ------------------------------------------
       
            When we start, we test if space (al=20h) and then the sign.
           
            Whenever we start IntegerPart or DecimalPart or ExponentPart
            we test if space (al=20h.)

            If we are in IntegerPart or ExponentPart, then we test sign
            and then we test space or zeros (may be -000555).

       ---------------------------
    D2.    removing zeroes
       ---------------------------

            In cases like 000000123.25E00032 the integer part has not 9 digits but 3 
            So, while it is '0', get another and dont go to the next step.

       ---------------------------
    D3.         errors
       ---------------------------

        We have 3 types of erros:

            1. user erros

                a) expression error
               
                b) unacceptable character
               
                c) more than 8 integer digits
               
                d) more than 7 decimal digits
               
                e) more than 2 exponet digits

            2. programming errors

                a) undefined pointers

            3. FPU errors
           
                a) invalid operation

                b) overflow/underflow

                c) Indefinite or NAN number


       -------------------------------------------
       D.4  To multiply by 10 and add eax
       -------------------------------------------

            solution 1: lea  edx, [edx+edx*4]
                        lea  edx, [eax+edx*2]

            solution 2: imul edx, 10
                        add  edx, eax
            ...
           
       ---------------------------
    E.      Real4 format
       ---------------------------

            offset: +0                 +16        +22         +31
                    ---------------------------------------------
                    |f23               |          f1|e0     e7|S|
                    ---------------------------------------------

        a)  S bit 31 = sign -> 0 = positive, 1= negative

            to test sign bit:     «test eax, 80000000H»   or  «and eax, 80000000H»

        b) 8 exponent bits: bits e0-e7 , from offset 23 to 30

            to extract exponent bits:      «and eax, 7F800000H» 
           
                                        or «shl eax, 23»
                                           «and eax, 0FFh»

                                exponent bits
                                -------------
               exponent  < 0  ->   < 7Fh
            if exponent  = 0  ->   = 7Fh=127   (real expoent=0 => exponent bits=7Fh)
               exponent  > 0  ->   > 7Fh

            if expoent bits = FFh => NAN

            if NAN and fraction bits= 0 => INFINITY (S=0 => +infinity S=1 => -infinity)

            if NAN and fraction bits= 1 => INDEFINITE


        c) 23 fraction bits: bits f1 - f23, from offset 0 to 22

            to extract fraction bits:      «and eax, 07FFFFFH»

        -------------------------------
    F.   test real4 format in EAX
        -------------------------------
        move a dword from memory to eax.
        If it is in st(0), move it to memory
       
        output:
       
            stc:   is Indefinite or NAN

            clc:   is a number (not infinity)

        TestReal4       proc
       
                        or      eax, eax
                        jz      short @F
                                               
                        shr     eax, 23      ; exponent and sign in AX; AH=sign AL=exponent
                        cmp     al, 0FFh
                        je      short _isNan
                       
                        ; ---------------
                        ; is real4 number
                        ; ---------------
                @@:     clc
                        ret
                        ; --------------------------------
                        ; is INFINITY or INDEFINITY or NAN
                        ; --------------------------------
            _isNan:     stc
                        ret                       
        TestReal4       endp

        --------------------------------------
        examine 1 real4 format in EAX
        --------------------------------------
        move a dword from memory to eax
        If it is in st(0), move it to memory
       
        output:
       
            stc:   is Indefinite or NAN

            clc:    EAX = 0     is 0
                        = 1     is +INFINITY
                        = 2     is -INFINITY
                        = 3     is POSITIVE
                        = 4     is NEGATIVE

        Examine1Real4   proc
       
                        or      eax, eax
                        jnz     short @F
                       
                        ; -------------
                        ; is 0 -> EAX=0
                        ; -------------
                        clc
                        ret
                       
            @@:     mov     edx, eax
                        shr     edx, 23  ;exponent and sign in DX; DH=sign DL=exponent
                        and     eax, 07FFFFFH   ; fraction in EAX
                        ;
                        cmp     dl, 0FFh
                        je      short _isNan
                       
                        ; ---------------
                        ; is real4 number
                        ; ---------------
                        mov     eax, 3
                        shr     dh, 1
                        jnc     short _isRealP
                        ; -----------
                        ; is negative
                        ; -----------
                        add     eax, 1
                        ; -----------
                        ; is positive
                        ; -----------
        _isRealP:       clc
                        ret

        _isNan:         or      eax, eax
                        jz      short _isInfinity
                   
                        ; --------------------
                        ; is indefinite or NAN
                        ; --------------------
                        stc
                        ret

        _isInfinity:    mov     eax, 3
                        shr     dh, 1
                        jnc     short _isInfinityP

                        ; ------------
                        ; is -infinity
                        ; ------------
                        add     eax, 1

                        ; ------------
                        ; is +infinity
                        ; ------------
        _isInfinityP:   stc
                        ret
        Examine1Real4   endp

        -------------------------------------
        examine 2 real4 format in EAX
        --------------------------------------
        move a dword from memory to eax
        If it is in st(0), move it to memory
       
        output:
       
            stc:   is Indefinite or NAN

            clc:    EAX = 0     is a number
                        = 1     is INFINITY

        Examine2Real4   proc
       
                        or      eax, eax
                        jnz     short @F
                       
                        ; -------------
                        ; is 0 -> EAX=0
                        ; -------------
            _isNumber:  xor     eax, eax
                        clc
                        ret
                       
            @@:     mov     edx, eax
                        shr     edx, 23    ; exponent and sign in DX; DH=sign DL=exponent
                        and     eax, 07FFFFFH   ; fraction in EAX
                        ;
                        cmp     dl, 0FFh
                        jne     short _isNumber
                       
                        or      eax, eax
                        jz      short _isInfinity
                   
                        ; --------------------
                        ; is indefinite or NAN
                        ; --------------------
                        stc
                        ret

        _isInfinity:    mov     eax, 1
                        clc
                        ret
        Examine2Real4   endp

Gunther

Hi RuiLoureiro,

good explanation and a good refresher.  :t

Gunther
You have to know the facts before you can distort them.

GoneFishing

Hi RuiLoureiro!
Here are tests for Celeron D:
TestCnvDD9:
ConvertString4YF
1234.0

ConvertString4T
1234.0

ConvertString4TX
1234.0

ConvertString4TY
1234.0

ConvertString4TW
1234.0

ConvertString4T4
1234.0

ConvertString4D
1234.0

ConvertString4DS
1234.0

*** STOP RclStr01 +1234 ***
converting _RclStr02 .567

ConvertString4B
1 ERROR eax
ConvertString4BX
1 ERROR eax
ConvertString4BZ
1 ERROR eax
ConvertString4BY
1 ERROR eax
ConvertString4BW
1 ERROR eax
ConvertString4BF
1 ERROR eax
ConvertString4Y0
0.567

ConvertString4Y
0.567

ConvertString4YM
0.567

ConvertString4YF
0.567

ConvertString4T
0.567

ConvertString4TX
0.567

ConvertString4TY
0.567

ConvertString4TW
0.567

ConvertString4T4
0.567

ConvertString4D
0.567

ConvertString4DS
0.567

*** STOP RclStr02 .567 ***
converting _RclStr03 E+12

ConvertString4B
1 ERROR eax
ConvertString4BX
1 ERROR eax
ConvertString4BZ
1 ERROR eax
ConvertString4BY
1 ERROR eax
ConvertString4BW
1 ERROR eax
ConvertString4BF
1 ERROR eax
ConvertString4Y0
1 ERROR eax
ConvertString4Y
1 ERROR eax
ConvertString4YM
1 ERROR eax
ConvertString4YF
1 ERROR eax
ConvertString4T
1 ERROR eax
ConvertString4TX
1 ERROR eax
ConvertString4TY
1 ERROR eax
ConvertString4TW
1 ERROR eax
ConvertString4T4
1 ERROR eax
ConvertString4D
1 ERROR eax
ConvertString4DS
1 ERROR eax
*** STOP RclStr03 E+12 ***
converting _RclStr04 +1234.567

ConvertString4B
1234.567

ConvertString4BX
1234.567

ConvertString4BZ
1234.567

ConvertString4BY
1234.567

ConvertString4BW
1234.567

ConvertString4BF
1234.567

ConvertString4Y0
1234.567

ConvertString4Y
1234.567

ConvertString4YM
1234.567

ConvertString4YF
1234.567

ConvertString4T
1234.567

ConvertString4TX
1234.567

ConvertString4TY
1234.567

ConvertString4TW
1234.567

ConvertString4T4
1234.567

ConvertString4D
1234.567

ConvertString4DS
1234.567

*** STOP RclStr04 +1234.567 ***
converting _RclStr05 +1234E+12

ConvertString4B
1.2339999E+15

ConvertString4BX
1.2339999E+15

ConvertString4BZ
1.2339999E+15

ConvertString4BY
1.2339999E+15

ConvertString4BW
1.2339999E+15

ConvertString4BF
1.2339999E+15

ConvertString4Y0
1.2339999E+15

ConvertString4Y
1.2339999E+15

ConvertString4YM
1.2339999E+15

ConvertString4YF
1.2339999E+15

ConvertString4T
1.2339999E+15

ConvertString4TX
1.2339999E+15

ConvertString4TY
1.2339999E+15

ConvertString4TW
1.2339999E+15

ConvertString4T4
1.2339999E+15

ConvertString4D
1.2339999E+15

ConvertString4DS
1.2339999E+15

*** STOP RclStr05 +1234E+12 ***
converting _RclStr06 .567E+12

ConvertString4B
1 ERROR eax
ConvertString4BX
1 ERROR eax
ConvertString4BZ
1 ERROR eax
ConvertString4BY
1 ERROR eax
ConvertString4BW
1 ERROR eax
ConvertString4BF
1 ERROR eax
ConvertString4Y0
5.6699997E+11

ConvertString4Y
5.6699997E+11

ConvertString4YM
5.6699997E+11

ConvertString4YF
5.6699997E+11

ConvertString4T
5.6699997E+11

ConvertString4TX
5.6699997E+11

ConvertString4TY
5.6699997E+11

ConvertString4TW
5.6699997E+11

ConvertString4T4
5.6699997E+11

ConvertString4D
5.6699997E+11

ConvertString4DS
5.6699997E+11

*** STOP RclStr06 .567E+12 ***
converting _RclStr07 +1234.567E+12

ConvertString4B
1.234567E+15

ConvertString4BX
1.234567E+15

ConvertString4BZ
1.234567E+15

ConvertString4BY
1.234567E+15

ConvertString4BW
1.234567E+15

ConvertString4BF
1.234567E+15

ConvertString4Y0
1.234567E+15

ConvertString4Y
1.234567E+15

ConvertString4YM
1.234567E+15

ConvertString4YF
1.234567E+15

ConvertString4T
1.234567E+15

ConvertString4TX
1.234567E+15

ConvertString4TY
1.234567E+15

ConvertString4TW
1.234567E+15

ConvertString4T4
1.234567E+15

ConvertString4D
1.234567E+15

ConvertString4DS
1.234567E+15

*** STOP RclStr07 +1234.567E+12 ***
converting _RclStr08 +000000 012 34.56 7 E + 000012

ConvertString4B
3 ERROR eax
ConvertString4BX
3 ERROR eax
ConvertString4BZ
3 ERROR eax
ConvertString4BY
3 ERROR eax
ConvertString4BW
3 ERROR eax
ConvertString4BF
1 ERROR eax
ConvertString4Y0
1 ERROR eax
ConvertString4Y
1.234567E+15

ConvertString4YM
1.234567E+15

ConvertString4YF
1.234567E+15

ConvertString4T
1.234567E+15

ConvertString4TX
1.234567E+15

ConvertString4TY
1.234567E+15

ConvertString4TW
1.234567E+15

ConvertString4T4
1.234567E+15

ConvertString4D
1.234567E+15

ConvertString4DS
1.234567E+15

*** STOP RclStr08 +000000 012 34.56 7 E + 000012 ***
converting _RclStr09 +1.234E+45

ConvertString4B
8 ERROR eax
ConvertString4BX
8 ERROR eax
ConvertString4BZ
8 ERROR eax
ConvertString4BY
8 ERROR eax
ConvertString4BW
8 ERROR eax
ConvertString4BF
8 ERROR eax
ConvertString4Y0
8 ERROR eax
ConvertString4Y
8 ERROR eax
ConvertString4YM
8 ERROR eax
ConvertString4YF
8 ERROR eax
ConvertString4T
8 ERROR eax
ConvertString4TX
8 ERROR eax
ConvertString4TY
8 ERROR eax
ConvertString4TW
8 ERROR eax
ConvertString4T4
8 ERROR eax
ConvertString4D
8 ERROR eax
ConvertString4DS
8 ERROR eax
*** STOP RclStr09 +1.234E+45 ***
converting _RclStr10 +1.234E-45

ConvertString4B
8 ERROR eax
ConvertString4BX
8 ERROR eax
ConvertString4BZ
8 ERROR eax
ConvertString4BY
8 ERROR eax
ConvertString4BW
8 ERROR eax
ConvertString4BF
8 ERROR eax
ConvertString4Y0
7 ERROR eax
ConvertString4Y
1.4012985E-45

ConvertString4YM
1.4012985E-45

ConvertString4YF
1.4012985E-45

ConvertString4T
1.4012985E-45

ConvertString4TX
1.4012985E-45

ConvertString4TY
1.4012985E-45

ConvertString4TW
1.4012985E-45

ConvertString4T4
1.4012985E-45

ConvertString4D
1.4012985E-45

ConvertString4DS
1.4012985E-45

*** STOP RclStr10 +1.234E-45 and END ***


TestCncDD10:
Quoteconverting _RclStr04 +1234.567

2566 cycles, ConvertString4, _RclStr04

2662 cycles, ConvertString4BX, _RclStr04

603 cycles, ConvertString4BZ, _RclStr04

561 cycles, ConvertString4BY, _RclStr04

446 cycles, ConvertString4BW, _RclStr04

465 cycles, ConvertString4BF, _RclStr04

113 cycles, ConvertString4Y0, _RclStr04

128 cycles, ConvertString4Y, _RclStr04

135 cycles, ConvertString4YM, _RclStr04

125 cycles, ConvertString4YF, _RclStr04

239 cycles, ConvertString4T, _RclStr04

181 cycles, ConvertString4TX, _RclStr04

174 cycles, ConvertString4TY, _RclStr04

157 cycles, ConvertString4TW, _RclStr04

218 cycles, ConvertString4T4, _RclStr04

115 cycles, ConvertString4D, _RclStr04

2221 cycles, ConvertString4DS, _RclStr04

*** STOP and END ***

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

113  cycles, ConvertString4Y0, direct - no spaces, no zeroes
115  cycles, ConvertString4D, direct
125  cycles, ConvertString4YF, direct
128  cycles, ConvertString4Y, direct
135  cycles, ConvertString4YM, direct
157  cycles, ConvertString4TW, code table
174  cycles, ConvertString4TY, code table
181  cycles, ConvertString4TX, xlatb
218  cycles, ConvertString4T4, code table
239  cycles, ConvertString4T, xlatb
446  cycles, ConvertString4BW, BCD
465  cycles, ConvertString4BF, BCD
561  cycles, ConvertString4BY, BCD
603  cycles, ConvertString4BZ, BCD
2221  cycles, ConvertString4D, direct, save FPU
2566  cycles, ConvertString4B, BCD, save FPU
2662  cycles, ConvertString4BX, BCD, save FPU
********** END **********

Thanks for your explanations on floating point basics . That's just what I want to understand (I'm among those trying to learn)
:t

dedndave

#5
going from a real to a string is fun
going from a string to a real is hard work   :t

i was wondering - without me reading 15 more miles of documentation
do the fraction bits have any meaning for NaN's ?

EDIT - i see they can carry a "payload"
not much in the way of a description, though - lol
other than it may be some sort of ordinal indicating where the problem originated

RuiLoureiro

Quote from: Gunther on April 15, 2013, 05:47:11 AM
Hi RuiLoureiro,

good explanation and a good refresher.  :t

Gunther

:biggrin:
                 Thanks  Gunther :t

RuiLoureiro

Quote from: vertograd on April 15, 2013, 07:59:41 PM
Hi RuiLoureiro!
...
Thanks for your explanations on floating point basics . That's just what I want to understand (I'm among those trying to learn)
:t

Hi vertograd  :t
                          I dont like to do things without some explanations
                          i was a teacher so...
                          And i try to be clear, but sometimes ... we dont know
                          Thanks
                          more: this converter was the best i did

RuiLoureiro

Quote from: dedndave on April 16, 2013, 12:47:51 AM
going from a real to a string is fun
going from a string to a real is hard work   :t

i was wondering - without me reading 15 more miles of documentation
do the fraction bits have any meaning for NaN's ?

Dave,
                            i dont know. I think that FPU set it to NAN when it fails to
                            do some operation and set fraction to 0 if beyond the limit.
                            We need to know the details about the hardware, thing
                            that i have no time now to follow.

dedndave

the special case values for REAL4 and REAL8 are pretty simple   :biggrin:
a few more caveats when you do REAL10

RuiLoureiro

Quote from: dedndave on April 20, 2013, 07:19:12 AM
the special case values for REAL4 and REAL8 are pretty simple   :biggrin:
a few more caveats when you do REAL10
What ? the calculator works with real10, i dont know any problems  :biggrin:

dedndave

my mistake, Rui   :redface:

i guess going from Ascii Decimal to REAL, you don't encounter all the caveats
it either fits or it doesn't - lol
and if it doesn't fit, you can assign the largest or smalllest value that does fit   :biggrin:

i was thinking about going from REAL to Ascii Decimal
the REAL4 and REAL8 formats are a little simpler than REAL10

REAL4/REAL8
Exponent   Fraction   Meaning

   0          0       Signed Zero
   0        <> 0      Signed Denormal
Other       Any      Signed Normal
All 1's       0       Signed Infinity
All 1's     <> 0      NaN


REAL10
  Exponent                     Significand                  Meaning

    0000       0000_0000_0000_0000                          Signed Zero
               0000_0000_0000_0001 to 7FFF_FFFF_FFFF_FFFF   Signed Denormal
               8000_0000_0000_0000 to FFFF_FFFF_FFFF_FFFF   Signed Pseudo-Denormal

0001 to 7FFE   0000_0000_0000_0000 to 7FFF_FFFF_FFFF_FFFF   Invalid
               8000_0000_0000_0000 to FFFF_FFFF_FFFF_FFFF   Signed Normal

    7FFF       0000_0000_0000_0000 to 7FFF_FFFF_FFFF_FFFF   Invalid
               8000_0000_0000_0000                          Signed Infinity
               8000_0000_0000_0001 to BFFF_FFFF_FFFF_FFFF   Signaling NaN
               C000_0000_0000_0000                          Indefinite Quiet NaN
               C000_0000_0000_0001 to FFFF_FFFF_FFFF_FFFF   Quiet NaN

RuiLoureiro

Good to know, Dave !  :t
One of these days i will use that info

RuiLoureiro

Quote
REAL10
  Exponent                     Significand                  Meaning

    0000       0000_0000_0000_0000                          Signed Zero
               0000_0000_0000_0001 to 7FFF_FFFF_FFFF_FFFF   Signed Denormal
               8000_0000_0000_0000 to FFFF_FFFF_FFFF_FFFF   Signed Pseudo-Denormal

0001 to 7FFE   0000_0000_0000_0000 to 7FFF_FFFF_FFFF_FFFF   Invalid
               8000_0000_0000_0000 to FFFF_FFFF_FFFF_FFFF   Signed Normal

    7FFF       0000_0000_0000_0000 to 7FFF_FFFF_FFFF_FFFF   Invalid
               8000_0000_0000_0000                  Signed Infinity
               8000_0000_0000_0001 to BFFF_FFFF_FFFF_FFFF   Signaling NaN
               C000_0000_0000_0000                          Indefinite Quiet NaN
               C000_0000_0000_0001 to FFFF_FFFF_FFFF_FFFF   Quiet NaN
Dave,
          when exponent is 7FFF

is this -Infinity ?
8000_0000_0000_0000                  Signed Infinity
so this is +Infinity, no ?
0000_0000_0000_0000                  Signed Infinity

So, where is the bit 79 = sign bit ?
If the S+exponent = 7FFFh -> sign = +
                              = FFFFh -> sign = -
Where is the problem ?

dedndave

the problem is, you are looking at info for the REAL10 format
there are 10 bytes, or 5 words - you are looking at 4 words   :P
the first column shows the exponent, bits 78 to 64
the second column shows the significand, bits 63 to 0

+infinity = 7FFF_8000_0000_0000_0000
-infinity = FFFF_8000_0000_0000_0000