flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > INF NaN data directives extension

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 636
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
Post 14 May 2021, 00:50
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18074
Location: In your JS exploiting you and your system
revolution
I think this line needs looking into:
Code:
@float.mantisa          = $004FFFFF    
Isn't it 0x007fffff?
Post 14 May 2021, 22:53
View user's profile Send private message Visit poster's website 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.