1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-14 19:05:15 +00:00
Funkin/source/funkin/util/tools/Int64Tools.hx
2023-08-03 22:22:29 -04:00

33 lines
823 B
Haxe

package funkin.util.tools;
/**
* @see https://github.com/fponticelli/thx.core/blob/master/src/thx/Int64s.hx
*/
class Int64Tools
{
static var min = haxe.Int64.make(0x80000000, 0);
static var one = haxe.Int64.make(0, 1);
static var two = haxe.Int64.ofInt(2);
static var zero = haxe.Int64.make(0, 0);
static var ten = haxe.Int64.ofInt(10);
public static function toFloat(i:haxe.Int64):Float
{
var isNegative = false;
if (i < 0)
{
if (i < min) return -9223372036854775808.0; // most -ve value can't be made +ve
isNegative = true;
i = -i;
}
var multiplier = 1.0, ret = 0.0;
for (_ in 0...64)
{
if (haxe.Int64.and(i, one) != zero) ret += multiplier;
multiplier *= 2.0;
i = haxe.Int64.shr(i, 1);
}
return (isNegative ? -1 : 1) * ret;
}
}