-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional Mathematical Constants and Functions #117
base: master
Are you sure you want to change the base?
Additional Mathematical Constants and Functions #117
Conversation
I'd make a new function for the min/max thing, but I don't know what to call it. The rest doesn't really need a haxe-evolution, but rather an implementation... |
If |
Not a fan of lerp, but the rest would be nice. |
A huge +1 for idiv from me. This is really annoying to do in Haxe at the moment and it shouldn't be. |
If expanding Well... at least according to some languages such as Java, it would exist as part of the standard |
Let's please stay focused here, this is (and should be) about changes to the |
If you feel the standard library deserves a BigInteger then you are free to write a separate proposal for that |
It would be great to have it monomorph to the right data type so that you can get a lot of these algorithms as int or float. Or at the very least. min and max should do that. I'm always doing this: @:generic
static public inline function min<T:Float>(x:T, y:T):T
{
return x > y ? y : x;
} Some we have different versions based on what type it returns ( |
Very much agree that min and max should gracefully handle floats V. ints. But, to be nit picky, I would do this via overloading, especially if Eric is proposing variadic min/max, and because I've had issues with <T:Float> uses like this in the past class Test
{
static function main()
{
// use simpler methods for 2 args
$type(min(1 , 2 )); // type: Int , output: 2 ints
$type(min(1 , 2.0 )); // type: Float, output: 2 floats
$type(min(1.0, 2 )); // type: Float, output: 2 floats
$type(min(1.0, 2.0 )); // type: Float, output: 2 floats
// more than two args
$type(min(1 , 2 , 3)); // type: Int , output: variadic ints
$type(min(1.0, 2.0, 3)); // type: Float, output: variadic floats
}
inline extern overload static function min(a:Int, b:Int):Int
{
trace("2 ints");
return a < b ? a : b;
}
inline extern overload static function min(...args:Int):Int
{
trace("variadic ints");
return minVInt(args.toArray());
}
static function minVInt(args:Array<Int>):Int
{
var result = args[0];
for (arg in args)
{
if (result > arg)
result = arg;
}
return result;
}
inline extern overload static function min(a:Float, b:Float):Float
{
trace("2 floats");
return a < b ? a : b;
}
inline extern overload static function min(...args:Float):Float
{
trace("variadic floats");
return minVFloat(args.toArray());
}
static function minVFloat(args:Array<Float>):Float
{
var result = args[0];
for (arg in args)
{
if (result > arg)
result = arg;
}
return result;
}
} Also note that your generic implementation fails on |
This proposal would implement several additional constants and functions into
Math
.This proposal started when I realized
Math.E
didn't exist, and expanded as I thought about the main inconveniences ofMath
(i.e. having to nestMath.min
calls and having to wrap many functions inStd.int
even when the inputs were integers to begin with).Feel free to suggest any additional functions to provide or critique the proposal.