flat assembler
Message board for the users of flat assembler.

Index > Main > How I can to declare of abnormal float-numbers as constants?

Author
Thread Post new topic Reply to topic
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
I need to declare abnormal numbers in the form of constants. In HLL this constans decaled as, for example, in Delphi, Data:double=1.0/0.0; //Infinity, but FASM refuses to compile this expressions. Certainly, it's possible to calculate it during performance, but the given problem very much becomes complicated in my case.
Post 27 Feb 2007, 16:28
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
infinity dd 2139095040
Post 27 Feb 2007, 20:20
View user's profile Send private message Reply with quote
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
Plue: Do you can post constants for negative infinity, QNAN and other and for all float types (single, double, extended)? Or, if you can, give me some urls for info about it?
Post 27 Feb 2007, 22:00
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
Code:
        PRECISION       = 32

        if PRECISION    = 32
          PLUS          = 0 shl 31
          MINUS         = 1 shl 31
          DENORMALIZED  = 1 shl 22
          INFINITY      = ((1 shl 8) - 1) shl 23
          NAN           = DENORMALIZED or INFINITY
        else if PRECISION = 64
          PLUS          = 0 shl 63
          MINUS         = 1 shl 63
          DENORMALIZED  = 1 shl 51
          INFINITY      = ((1 shl 11) - 1) shl 52
          NAN           = DENORMALIZED or INFINITY
;        else if PRECISION = 80
;          PLUS          = 0 shl 79
;          MINUS         = 1 shl 79
;          DENORMALIZED  = 1 shl 65
;          INFINITY      = ((1 shl 15) - 1) shl 66
;          NAN           = DENORMALIZED or INFINITY
        end if

        denormalized    dd DENORMALIZED
        infinity        dd INFINITY or MINUS ; -infinity
        nan             dd NAN
    
Remember to adjust PRECISION constant to the data you in fact declare. Also the 80 bits precision doesn't work Smile. Tomasz disallows using anything but floats with 'dt'. It only accepts 1.0, 3.14, etc. The 80 bits block is just put here, because maybe you'll dig into macros to enable its usage - it is possible, I'm just too lazy to create it Razz.
EDIT: Oh I forgot fasm uses 64-bit numbers so no chance for compiler-time 80 bits INFINITY ot NAN, this one can be only saved during runitme :/.
Post 27 Feb 2007, 22:22
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
Quote:
EDIT: Oh I forgot fasm uses 64-bit numbers so no chance for compiler-time 80 bits INFINITY ot NAN, this one can be only saved during runitme :/.
Really? You can declare each with two dds and a dw, but you'll need a hardcoded macro for that
Post 28 Feb 2007, 14:14
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Code:
macro dt [arg] {
  else equ 1
  match =NAN, arg \{
    dd ...
    dd ...
    dw ...
    restore else
    else equ 0
  \}
  match =-=NAN, arg \{
    dd ...
    dd ...
    dw ...
    restore else
    else equ 0
  \}
  ... etc ...
  match =1, else \{
    dt arg
  \}
  restore else
}    


that's the idea. Additionaly you can add checking for "+NAN" etc..
Post 28 Feb 2007, 14:32
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Don't forget to define "struc dt ..." also making use of that macro.
Post 28 Feb 2007, 14:41
View user's profile Send private message Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend
OK, I underestimated fasm's power Smile. But from now it's Garthower's task to make the macro work if he needs 80 bits NANS and INFINITIES - I'm too lazy, and besides I don't need it at all ;]
Post 28 Feb 2007, 17:07
View user's profile Send private message Visit poster's website Reply with quote
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
Thanks for info. Using data from Reverend I create constants with db directive. Here they are:

Code:
@FcInfinity_Ext:        db 7Fh,0FFh,80h,00h,00h,00h,00h,00h,00h,00h     ;1.0/0.0
@FcNan_Ext:             db 0FFh,0FFh,0C0h,00h,00h,00h,00h,00h,00h,00h   ;0.0/0.0
@FcnInfinity_Ext:       db 0FFh,0FFh,80h,00h,00h,00h,00h,00h,00h,00h    ;-1.0/0.0
@FcInfinity_Double:     db 7Fh,0F0h,00h,00h,00h,00h,00h,00h     ;1.0/0.0
@FcNan_Double:          db 0FFh,0F8h,00h,00h,00h,00h,00h,00h    ;0.0/0.0
@FcnInfinity_Double:    db 0FFh,0F0h,00h,00h,00h,00h,00h,00h    ;-1.0/0.0
@FcInfinity_Single:     db 7Fh,80h,00h,00h              ;1.0/0.0
@FcNan_Single:          db 0FFh,0C0h,00h,00h            ;0.0/0.0
@FcnInfinity_Single:    db 0FFh,080h,00h,00h            ;-1.0/0.0
    


I hope in future FASM's builds Tomasz will add an opportunity of record of similar numbers without any cunnings.
Post 01 Mar 2007, 08:40
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Garthower: slightly better version:

Code:
label @FcInfinity_Ext tbyte
db 7Fh,0FFh,80h,00h,00h,00h,00h,00h,00h,00h     ;1.0/0.0 

label @FcNan_Ext tbyte
db 0FFh,0FFh,0C0h,00h,00h,00h,00h,00h,00h,00h   ;0.0/0.0 

...

label @FcInfinity_Double qword
db 7Fh,0F0h,00h,00h,00h,00h,00h,00h     ;1.0/0.0 

...

label @FcInfinity_Single dword
db 7Fh,80h,00h,00h              ;1.0/0.0 

...    
Post 01 Mar 2007, 10:56
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
By the way? is this correct? Little endian or big?
Post 01 Mar 2007, 11:04
View user's profile Send private message Reply with quote
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
Yes, you are right vid. So it will not be need in manual to specify type of data in commands. Thanks!
Post 01 Mar 2007, 11:04
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
asmfan wrote:
By the way? is this correct? Little endian or big?


Sorry, my english is not so well, but what do you mean in word "endian"?
Post 01 Mar 2007, 11:09
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
endianness means which byte comes first. For example, is 1234ABCDh this:
Code:
db 12h, 34h, 0ABh, 0CDh    

or
Code:
db 0CDh, 0ABh, 34h, 12h    


for more info consult wikipedia Smile
Post 01 Mar 2007, 11:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
Thanks vid again, I undertood Smile
2asmfan: Yes, it's a correct constants with currect endian Wink
Post 01 Mar 2007, 11:17
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
Guys, your constants need to be byteswapped to be correct - that's all i meant.
Post 01 Mar 2007, 11:35
View user's profile Send private message Reply with quote
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
asmfan wrote:
Guys, your constants need to be byteswapped to be correct - that's all i meant.


These constants are in Intel format, i.e. in little endian. And you should solve, as to you they should be rearranged.
Post 01 Mar 2007, 12:30
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan
Les's say no words and run Olly. try to load your constants as if they little endian and you'll see what is correct.
Post 01 Mar 2007, 12:40
View user's profile Send private message Reply with quote
Garthower



Joined: 21 Apr 2006
Posts: 158
Location: Ukraine
Garthower
2asmfan:: Oh, you are right Sad For normal using it must be rearranged. I'm so sorry for post incorect values.

Here are tested constants with vid recomendation:
Code:
label @FcInfinity_Ext   tbyte
                      db 00h,00h,00h,00h,00h,00h,00h,80h,0FFh,7Fh       ;1.0/0.0
label @FcNan_Ext        tbyte
                      db 00h,00h,00h,00h,00h,00h,00h,0C0h,0FFh,0FFh     ;0.0/0.0
label @FcnInfinity_Ext  tbyte
                      db 00h,00h,00h,00h,00h,00h,00h,80h,0FFh,0FFh      ;-1.0/0.0
label @FcInfinity_Double qword
                      db 00h,00h,00h,00h,00h,00h,0F0h,7Fh       ;1.0/0.0
label @FcNan_Double     qword
                      db 00h,00h,00h,00h,00h,00h,0F8h,0FFh      ;0.0/0.0
label @FcnInfinity_Double qword
                      db 00h,00h,00h,00h,00h,00h,0F0h,0FFh      ;-1.0/0.0
label @FcInfinity_Single dword
                      db 00h,00h,80h,7Fh                ;1.0/0.0
label @FcNan_Single     dword
                      db 00h,00h,0C0h,0FFh              ;0.0/0.0
label @FcnInfinity_Single dword
                      db 00h,00h,080h,0FFh              ;-1.0/0.0
    
Post 01 Mar 2007, 13:14
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.