Created
April 2, 2014 22:23
-
-
Save martinwells/9944457 to your computer and use it in GitHub Desktop.
Convert an int64 to a float and back
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.Int64; | |
class Int64Utils | |
{ | |
private inline static var MAX_32_PRECISION = 4294967296; | |
public static function fromFloat(f:Float):Int64 { | |
return Int64.make(Std.int(f/MAX_32_PRECISION), Std.int(f-(f/MAX_32_PRECISION))); | |
} | |
public static function toFloat(i:Int64):Float { | |
return (Int64.getHigh(i) * MAX_32_PRECISION + Int64.getLow(i)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See HaxeFoundation/haxe#3655 for a fromFloat