Float | Int - Max-Values?

1,146 views
Skip to first unread message

der Raab

unread,
Oct 5, 2015, 4:54:06 PM10/5/15
to Haxe
Hi! In the old ActionScript days I simply relied on constants like Number.MAX_VALUE (or MIN_VALUE) representing the biggest possible value. So I wonder if these constants are somewhere available in Haxe. I'm quite sure these values differ from target to target...

Mark Knol

unread,
Oct 5, 2015, 6:40:27 PM10/5/15
to Haxe
I use them from Flambe https://github.com/aduros/flambe/blob/master/src/flambe/math/FMath.hx

It would be nice to have it in the Haxe Standard Lib somewhere.

Will Maynard

unread,
Oct 5, 2015, 6:52:45 PM10/5/15
to Haxe
Hi der Raab,

I actually had a similar need when I was working on a math-y project (Project Euler) - I'm used to an Int.MAX value as well.  I just brute-forced the values.  It's probably not as eloquent as using someone else's library but part of the goal was to do it myself anyway.

On the first run of my app on a system, it iterates through an integer value and stores the maximum in a text file for future use - this way, I don't need to run through those loops again.  (If that text file does not exist, the app hasn't been run yet).

I've done this for other data types, too, but here is the MWE for it:

class Main extends MovieClip
{
public static function main():Void
{
Max.init();
trace(Max.INT); // 2147483647
}
}
class Max
{
public static var INT:Int;

/* ... */

public static function init():Void
{
var intOverflow:Int = 0;
while (++intOverflow > 0)
INT = intOverflow;
}
}

-Will

der Raab

unread,
Oct 6, 2015, 1:48:10 AM10/6/15
to Haxe
Thank you both! While Wills approach seems to provide an more accurate solution (and I will consider that later) for my use it's perfectly fine to use the lowest common value. So I'll copy paste from flambe. Great! 
Reply all
Reply to author
Forward
0 new messages