flat assembler
Message board for the users of flat assembler.

 Index > Tutorials and Examples > INF NaN data directives extension
Author
ProMiNick

Joined: 24 Mar 2012
Posts: 687
Location: Russian Federation, Sochi
ProMiNick
Code:
```@float.exponent         = \$7F800000
@float.firstNaN         = \$7F800001
@float.halfsign         = \$40000000
@float.mantisa          = \$007FFFFF ; fixed, thanks revolution

@double.exponent        = \$7FF0000000000000
@double.firstNaN        = \$7FF0000000000001
@double.halfsign        = \$4000000000000000
@double.mantisa         = \$000FFFFFFFFFFFFF

@ext.exponent           = \$7FFF
@ext.halfsign           = \$4000
@ext.infinity           = \$8000000000000000
@ext.firstNaN           = \$8000000000000001
@ext.mantisa            = \$7FFFFFFFFFFFFFFF

struc dd [arg] {
if defined arg
. dd arg
else
match sign value,arg {
match =INF,value           { . dd @float.exponent - (sign @float.halfsign - @float.halfsign) \\}
match =NaN,value           { . dd @float.firstNaN - (sign @float.halfsign - @float.halfsign) \\}
match =NaN + variant,value { . dd @float.firstNaN - (sign @float.halfsign - @float.halfsign) + ((variant+1) and @float.mantisa) - 1 and (((variant+1) and @float.mantisa)/(((variant) and @float.mantisa)+1)) \\} \}
end if }

macro dd [arg] {
if defined arg
dd arg
else
match sign value,arg {
match =INF,value           { dd @float.exponent - (sign @float.halfsign - @float.halfsign) \\}
match =NaN,value           { dd @float.firstNaN - (sign @float.halfsign - @float.halfsign) \\}
match =NaN + variant,value { dd @float.firstNaN - (sign @float.halfsign - @float.halfsign) + ((variant+1) and @float.mantisa) - 1 and (((variant+1) and @float.mantisa)/(((variant) and @float.mantisa)+1)) \\} \}
end if }

struc dq [arg] {
if defined arg
. dq arg
else
match sign value,arg {
match =INF,value           { . dq @double.exponent - (sign @double.halfsign - @double.halfsign) \\}
match =NaN,value           { . dq @double.firstNaN - (sign @double.halfsign - @double.halfsign) \\}
match =NaN + variant,value { . dq @double.firstNaN - (sign @double.halfsign - @double.halfsign) + ((variant+1) and @double.mantisa) - 1 and (((variant+1) and @double.mantisa)/(((variant) and @double.mantisa)+1)) \\} \}
end if }

macro dq [arg] {
if defined arg
dq arg
else
match sign value,arg {
match =INF,value           { dq @double.exponent - (sign @double.halfsign - @double.halfsign) \\}
match =NaN,value           { dq @double.firstNaN - (sign @double.halfsign - @double.halfsign) \\}
match =NaN + variant,value { dq @double.firstNaN - (sign @double.halfsign - @double.halfsign) + ((variant+1) and @double.mantisa) - 1 and (((variant+1) and @double.mantisa)/(((variant) and @double.mantisa)+1)) \\} \}
end if }

struc dt [arg] {
if 1.0 eqtype arg
. dt arg
else
match sign value,arg {
label . tbyte
match =INF,value { dq @ext.infinity \\}
match =NaN,value { dq @ext.firstNaN \\}
match =NaN + variant,value { dq @ext.firstNaN + ((variant+1) and @ext.mantisa) - 1 and (((variant+1) and @ext.mantisa)/(((variant) and @ext.mantisa)+1)) \\}
dw @ext.exponent - (sign @ext.halfsign - @ext.halfsign) \}
end if }

macro dt [arg] {
if 1.0 eqtype arg
dt arg
else
match sign value,arg {
match =INF,value { dq @ext.infinity \\}
match =NaN,value { dq @ext.firstNaN \\}
match =NaN + variant,value { dq @ext.firstNaN + ((variant+1) and @ext.mantisa) - 1 and (((variant+1) and @ext.mantisa)/(((variant) and @ext.mantisa)+1)) \\}
dw @ext.exponent - (sign @ext.halfsign - @ext.halfsign) \}
end if }    ```

this aproach has only 1 significant minus - when these data directives get something realy undefined they don`t signal error.
use case:
Code:
```dd 1, 7.6, +INF, -INF, +NaN, -NaN,+NaN+-1,-NaN+1000000+7/2 shl 4
dq 1, 7.6, +INF, -INF, +NaN, -NaN,+NaN+-1,-NaN+1000000+7/2 shl 4
dt 7.6, +INF, -INF, +NaN, -NaN,+NaN+-1,-NaN+1000000+7/2 shl 4    ```

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.

Last edited by ProMiNick on 17 May 2021, 05:51; edited 1 time in total
14 May 2021, 00:50
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 18758
revolution
I think this line needs looking into:
Code:
`@float.mantisa          = \$004FFFFF    `
Isn't it 0x007fffff?
14 May 2021, 22:53
Overclick

Joined: 11 Jul 2020
Posts: 524
Location: Ukraine
Overclick
WOW it is genius to use struc as macro for second element. It will help me a lot
03 Jul 2021, 02:44
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum