haxe
haxe copied to clipboard
Min/Max constants for numeric values
Haxe lacks min/max constants for numeric (Int
, Float
, UInt
) types.
There is an implementation in as3hx Float Int
Those constants could be added to Math
class or to corresponding base types (like Int.MAX
, Float.MIN
etc).
I can make PR ;)
++
Any luck with this?
This would totally help me too. If it's difficult to do with built-in types like Int
is it at least possible to offer it on additional targets? I'm often needing it on cpp, where it should be easy (using std::numeric_limits
).
use https://github.com/skial/min-max
That only provides for two types (Float and Int).
I thought about this a little yesterday and I think it would be better if the interface was more like how it is in c++, i.e., using a type parameter. This would allow one to write generic algorithms that could work on different integer types, rather than littering your code with conditionals or having to use macros:
function squareWave<T>(phase:T):T
{
if (phase > (NumericLimits<T>.max() + NumericLimits<T>.min() / 2)) {
return NumericLimits<T>.max();
} else {
return NumericLimits<T>.min();
}
}
edit: the above code would work on all numeric types, not just integer
Maybe increase priority on this issue or schedule for a release? This seems to be a very useful feature.
+1
Just ran into this, and it would definitely be nice to have built in