Parameter default value should be constant

Hello,

this line return a compiler error

public function getPosition(t : Float = Math.NaN) : Float

Parameter default value should be constant

Math.NaN isn’t a constant ?

Thanks

Nope.

static var NaN(default, null) : Float;

how to use

static var NaN(default, null) : Float;

in

public function getPosition(t : Float = Math.NaN) : Float
{
        //
}

Why not

But why does a getPosition function has a float paramter??

I think that this, thanks.

As a workaround, you could use a hard-coded value (such as -1) or you can use Null<Float>

public function getPosition (t:Null<Float> = null):Float {
    if (t == null) t = Math.NaN;
    ...
}
1 Like

For the record, here’s a shorter way of writing the exact same thing:

public function getPosition (?t:Float):Float {
1 Like