News:

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

Main Menu

Math10 library

Started by RuiLoureiro, June 29, 2012, 12:47:24 AM

Previous topic - Next topic

RuiLoureiro

Hi
    Here we have a math library of real10 numbers

    We can test each function using TestMath10

    We can find the documentation in the file Math10.txt

    Good Luck

EDIT : i replaced version 0.03 by  the last version 0.04

   We have more 2 procedures to convert real10 to ascci
    and ascii to real10 with 19 digits
                StrToRealCnv and RealToStrCnv

qWord

Quote from: RuiLoureiro on June 29, 2012, 12:47:24 AM
    We can test each function using TestMath10

    We can find the documentation in the file Math10.txt
We can not find the source :icon_confused:
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

i would say....
DLL ? - at that size, why not just make a static LIB   :P

RuiLoureiro

It's the version 0.01 !
I need to write more functions to that .dll
and it is not completed tested.

Questions:

    Are those procedures useful ?
    Is there some errors ?

dedndave

it's a nice collection of functions, Rui   :t

RuiLoureiro

Quote from: dedndave on June 30, 2012, 05:31:15 AM
it's a nice collection of functions, Rui   :t

Only you to say something, Dave
Thank you Dave  :t

We need a procedure to convert real10 to string
It will be in the next

jj2007

Quote from: RuiLoureiro on June 30, 2012, 05:49:00 AM
We need a procedure to convert real10 to string

REAL10 is a QWORD plus a dot or a dot and an exponent. You can use the known Qword2Ascii routines and insert a dot somewhere.

include \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   Inkey Str$("PI=%Jf", PI)
   Exit
end start

Output: PI=3.141592653589793238

The problem is to know where to insert the dot...

RuiLoureiro

Jochen,
        These are the results that i get using FPU  ;)
           
            e =  2.71828182845904509     18 digits
            PI=  3.14159265358979324     18   "       
Output:  PI=3.141592653589793238    <<-- Jochen

dedndave

some values can have 20 usable digits
most can have only 19 usable digits
i forget the numbers, but if the signifigant digits start with something like 18765.... or less, 20 usable digits are available
you can find the leading digits through a little experimentation


http://www.masmforum.com/board/index.php?topic=11781.msg89823#msg89823

jj2007

The mantissa of a REAL10 is 64 bit aka QWORD. So the number of usable digits depends on what a QWORD can deliver...

dedndave

but - it is scaled by the exponent
when converting binary to decimal, the number of usable digits shifts a little

RuiLoureiro

Hi
    Here we have a math library of real10 numbers version 0.02
    We can test each function using TestMath10

    We can find the documentation in the file Math10.txt
    In this version we have the functions:

        FncXaddY, FncXsubY,FncXmulY,FncXdivY
        and FncXcmpY

    We have also 4 procedures to convert real10
    to ascci.

    In TestMath10.exe, to change the number of digits
    type a number 6 up to 17 and press compute

Example:

Quote
.data
_decimal   dd 5
_digits    dd 17

X          dt -3.1345

; dont forget this DWORD before XBuffer 
               dd 0            ;<--- to length
XBuffer    db 27 dup (?)                         ; we need 27 here

.code
        invoke  CnvRelToRclT, addr X, addr XBuffer
        jc      error

        invoke  CnvRelToRclZ, addr X, addr XBuffer
        jc      error

        invoke  CnvRelToRcl, addr X, addr XBuffer, _decimal
        jc      error

        invoke  CnvRelToRclD, addr X, addr XBuffer, _digits
        jc      error


error:


    Good Luck

RuiLoureiro

Hi
    2 questions or 1 question 1 problem

1.
    Here we have a math library of real10 numbers version 0.03
    We can test each function using TestMath10
    We can find the documentation in the file Math10.txt

    We have more functions
    and we have a procedure to convert ASCII to REAL10:

            invoke  CnvRclToRel, pRcl, pReal
            jc          error

    In TestMath10.exe, if we want to show only N digits
    type N in the input box and press compute

2.
    When we run TestMath10 and press PREVIOUS we find
    the function (it is not used in Math10 library
    and when we run it we can see the BCD strings)
   
    a)  RclToRelCnv(-123456789012345678.987654321098765432E4914)

    If we press PREVIOUS again we find
    the function (it is in the Math10 library)

    b)  CnvRclToRel(-12345678901234567.987654321098765432E4915)

    In the case a) we use 18 integer digits and
    in the case b) we use 17 integer digits only

                -123456789012345678 <---- a)
                -12345678901234567  <---- b)

    It means that RclToRelCnv tries to convert 18 integer digits
                    and CnvRclToRel only                  17 integer digits

    In both cases press COMPUTE and see the results with 17 digits

                   -1 23456789012345678.9               <- input in RclToRelCnv
        a)   X= -1.2345678901234566E+4931

                   -1 2345678901234567.9                <- input in CnvRclToRel
        b)   X= -1.2345678901234568E+4931

    As we can see, the result of b) is correct
                      and the result of a) is INcorrect

    I dont know why, but my first conclusion is this:

             «we cannot convert 18 digits ASCII»

    Have you any other opinion ?
    Please answer this post   

    Good Luck
    and thanks

qWord

As you surely know, not all decimal numbers can be exactly represented as binary numbers. So the answer is:
"We can maybe convert N digits ASCII"
The shown results look correct (rounded).
MREAL macros - when you need floating point arithmetic while assembling!

RuiLoureiro

qWord,
       Thanks for reply !

Quote
The shown results look correct (rounded).

        Yes, rounded . ( we are talking of FPU only)
       
        It seems to me that i made nothing wrong
        and i show all details. We can change the numbers
        and compute to see what we get

Quote
So the answer is:
        "We can maybe convert N digits ASCII"

        I dont like the "maybe" when i know 1 case
        where it gives incorrect results. I think
        there are a lot of cases like that and
        i want to avoid a lot of them if possible
        So i prefer my conclusion.
        See the next

Quote
As you surely know, not all decimal numbers can be exactly represented
as binary numbers.

        From Ray tutorial:

        INTEGER DATA TYPES
        QWORD range   ±(2^63-1)  or  ±9223372036854775807

        I tried to think that if the limit is this 20 digit number
        if i use FBLD (Load BCD data from memory) with only 18 digits
        it should give the correct result

        Meanwhile, we can read the following, in the file
        FpuAtoFL in the fpulib. Raymond wrote this:

        «
        ; ... The number of digits (excluding all leading 0's and trailing
        ; decimal 0's) must not exceed 18.
        »

        and that told me we should have not problems in using 18 digits.
        But im wrong.
        This is why i want to show the problem in TestMath10
        Math10  library uses CnvRclToRel to convert 17 integer digits only.