Skip to content

Instantly share code, notes, and snippets.

@joeykrug
Created November 22, 2016 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeykrug/43f2cba0593c2216affc3fa567d97c32 to your computer and use it in GitHub Desktop.
Save joeykrug/43f2cba0593c2216affc3fa567d97c32 to your computer and use it in GitHub Desktop.
float
type float: [a, b, c]
macro float($x) + float($y):
if(!safeToAdd($x, $y)):
throw()
float($x + $y)
macro float($x) - float($y):
if(!safeToSubtract($x, $y)):
throw()
float($x - $y)
macro float($x) * float($y):
if(!safeToMultiply($x, $y)):
throw()
float($x * $y / 10^18)
macro float($x) / float($y):
if($y == 0):
throw()
float($x * 10^18 / $y)
macro unfloat($x):
$x / 10^18
macro floatfy($x):
float($x * 10^18)
macro float($x) = float($y):
$x = $y
macro with(float($x), float($y), $z):
with($x, $y, $z)
macro safeToAdd($a, $b):
$c = $a + $b
($c >= $a && $c >= $b)
macro safeToSubtract($a, $b):
($b <= $a)
macro safeToMultiply($a, $b):
$c = $a * $b
($a == 0 || ($c / $a) == $b)
def test():
a = floatfy(25)
b = a / floatfy(2)
c = b * b
return(unfloat(c))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment