Skip to content

Instantly share code, notes, and snippets.

@dockimbel
Created January 24, 2012 23:59
Show Gist options
  • Save dockimbel/1673659 to your computer and use it in GitHub Desktop.
Save dockimbel/1673659 to your computer and use it in GitHub Desktop.
Rough implementation of 64-bit integer subtraction
Red/System []
int64!: alias struct! [high [integer!] low [integer!]]
sub64: func [
a [int64!]
b [int64!]
return: [int64!]
/local
diff [int64!] offset [integer!]
][
diff: declare int64!
diff/high: a/high - b/high
diff/low: a/low - b/low
offset: diff/low
if negative? offset [offset: negate offset]
if a/low < offset [diff/high: diff/high - 1]
diff
]
a: declare int64!
b: declare int64!
a/high: 10
a/low: 10
b/high: 3
b/low: 3
c: sub64 a b
print-wide [c/high c/low]
a/high: 10
a/low: 2
b/high: 3
b/low: 6
c: sub64 a b
print-wide [c/high c/low]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment