News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

float$ macro and algo for testing

Started by jj2007, August 26, 2008, 03:48:53 PM

Previous topic - Next topic

jj2007

Quote from: ToutEnMasm on July 06, 2009, 05:33:13 AM

The math.sdk file (vc++2008 translate) have some important constants value defined.
Quote
M_PI   equ   < 3.14159265358979323846>
jj2007                    PI = 3.14159265358979324
Better is to use this file .

ToutEnMasm,

you should at least try 1. to read posts properly and 2. to understand them.

MichaelW

AFAIK a REAL10 cannot represent 21 digits. Using TC 3.0, for which the CRT does support an 80-bit long double, this code:

#include <math.h>
#include <stdio.h>
int main()
{
    long double pi10 = 3.14159265358979323846L;
    long double pif10;
    double pif8;
    asm {
        fldpi
        fstp pif10
        fldpi
        fstp pif8
    }
    printf( "3.14159265358979323846\n" );
    printf( "%.19Lf\n", (long double) pi10 );
    printf( "%.19Lf\n", (long double) pif10 );
    printf( "%.19f\n", (double) pif8 );
    getch();
    return 0;
}

Produces these results:

3.14159265358979323846
3.1415926535897932400
3.1415926535897932400
3.1415926535897931200

eschew obfuscation

jj2007

Quote from: MichaelW on July 06, 2009, 06:23:42 AM
AFAIK a REAL10 cannot represent 21 digits....
Produces these results:

3.14159265358979323846
3.1415926535897932400
3.1415926535897932400
3.1415926535897931200


Exactly. After a fldpi, Olly shows 3.1415926535897932380. The same identical value is obtained when pushing the value of 3.14159265358979323846 proposed by ToutEnMasm.

My new Str$ produces 3.14159265358979324, which is technically speaking more correct than the 32400 which wrongly pretends a higher precision, see here, point d.

ToutEnMasm


To jj2007,
Be cool , i was saying that the crt give all we need to use floating point.
atof,ftoa are very useful.
Add to this the strsafe librarie,and there is a lot of work to do with masm.
Useful comparisons can be made between the two.

jj2007

Quote from: ToutEnMasm on July 06, 2009, 07:57:46 AM

To jj2007,
Be cool , i was saying that the crt give all we need to use floating point.
atof,ftoa are very useful.
Add to this the strsafe librarie,and there is a lot of work to do with masm.
Useful comparisons can be made between the two.


I love useful comparisons. Please post some code showing the precision and the speed of your "alternatives". I suggest you use the value of 3.14159265358979323846 that you posted yourself.

ToutEnMasm


I am not microsoft,it's not my value.It's the value given by the math.h header file.

I this instant , the value can be put in a DT and is translate as this by a 32 bits
Quote
35 c2 68 21 a2 da 0f c9-00 40          ;dump of adress of the dt
view as follow by windbg
Quote
4000c90fdaa22168c235
fld accept the dt
After i need a viewer that can show 20 numbers after the virgul.
I will search




jj2007

Quote from: ToutEnMasm on July 06, 2009, 09:12:16 AM

After i need a viewer that can show 20 numbers after the virgul.


Hmmmm.... I thought you had already a "viewer":

Quote from: ToutEnMasm on July 06, 2009, 07:57:46 AM
the crt give all we need to use floating point.

herge


Hi JJ:

06:44 AM EST July 6 - Monday 2009
I thoght I saw a puddy Cat!

I like your avatar!

Regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

sinsi

Hah! so this is jj2007 vs ToutEnMasm! But we know who always wins between those two avatars... :lol
Light travels faster than sound, that's why some people seem bright until you hear them.

ToutEnMasm


MichaelW

Borland used the same value:

#define M_PI  3.14159265358979323846

As does MinGW:

#define M_PI  3.14159265358979323846

I think the idea was to exceed the ~19 digits that the FPU can handle and truncate the value at a point were the next digit was < 5.

3.1415926535897932384626433832795...
eschew obfuscation

dedndave

i thought that, with MASM, you could define it to as many places as you like, and the assembler rounds it to fit the define type
i suppose that leaves a big spot for the assembler to make a mistake - lol
(we all know how perfect MASM is, right?)
i guess that also means that different assemblers might yield different results
to fix that, define it in raw float bytes ?

jj2007

Good point - what can the FPU handle, internally? A snippet for inspiration:

   fldpi      ; we push the exact PI
   fst MyPI8      ; a REAL8 for crt_printf
   fstp MyPI      ; a REAL10 for Str$
   fld MyPI      ; original value
   mov al, byte ptr MyPI
   dec eax
   mov byte ptr MyPI, al
   fld MyPI
   inc eax
   mov byte ptr MyPI, al
   fld MyPI
   inc eax
   mov byte ptr MyPI, al
   fld MyPI
   inc eax
   mov byte ptr MyPI, al
   fld MyPI
   inc eax
   mov byte ptr MyPI, al
   fld MyPI
   inc eax
   mov byte ptr MyPI, al
   fld MyPI
   inc eax
   mov byte ptr MyPI, al
   fld MyPI
   int 3


ToutEnMasm

Results  with  the fpu viewer , (libcmt )
Three value of PI    jj_PI ,SDK_PI, flpi_value
Quote
   ;35 c2 68 21 a2 da 0f c9-00 40  ;dump of memory
   ;4000c90fdaa22168c235           ; the DT show by windbg
Quote
jj_PI  dt  thevalue
SDK_PI dt  the value
the two show the same value in memory  ;dump of memory
Print of values loaded in the fpu registers,the three are the same
Quote
3.14159265358979310000       ;float print
54442D18h                             ;hexa print   


   

MichaelW

Using TC 3.0 again, this (16-bit DOS) code displays the values in the vicinity of pi that the REAL10 format can represent. The basis for this code is here.
#include <math.h>
#include <stdio.h>
int main()
{
    long double pi10;
    int i=0;
    asm {
        fldpi
        fstp pi10
    }
    printf( "\t3.14159265358979323846\n" );
    asm {
        lea bx, pi10
        sub WORD PTR [bx], 10
        sbb WORD PTR [bx+2], 0
        sbb WORD PTR [bx+4], 0
        sbb WORD PTR [bx+6], 0
        sbb WORD PTR [bx+8], 0
    }
    printf( "%d\t%.19Lf\n", i-10, (long double) pi10 );
    for( i=1; i<60; i++ )
    {
        asm {
            lea bx, pi10
            add WORD PTR [bx], 1
            adc WORD PTR [bx+2], 0
            adc WORD PTR [bx+4], 0
            adc WORD PTR [bx+6], 0
            adc WORD PTR [bx+8], 0
        }
        if( i < 20 || i == 52 || i == 53 )
          printf( "%d\t%.19Lf\n", i-10, (long double) pi10 );
    }
    getch();
    return 0;
}

The representable values in the immediate vicinity of pi are so close together that the Borland CRT cannot display the differences. To see a difference, it was necessary to go 6 values down or 43 values up. Perhaps Olly can do better.

        3.14159265358979323846
-10     3.1415926535897932300
-9      3.1415926535897932300
-8      3.1415926535897932300
-7      3.1415926535897932300
-6      3.1415926535897932300
-5      3.1415926535897932400
-4      3.1415926535897932400
-3      3.1415926535897932400
-2      3.1415926535897932400
-1      3.1415926535897932400
0       3.1415926535897932400
1       3.1415926535897932400
2       3.1415926535897932400
3       3.1415926535897932400
4       3.1415926535897932400
5       3.1415926535897932400
6       3.1415926535897932400
7       3.1415926535897932400
8       3.1415926535897932400
9       3.1415926535897932400
42      3.1415926535897932400
43      3.1415926535897932500

eschew obfuscation