Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Dynamic.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <hxcpp.h>
#include <math.h>
#include <cmath>
#include <hxMath.h>
#include <stdio.h>

Expand Down Expand Up @@ -407,9 +407,17 @@ Dynamic::Dynamic(char32_t inVal)
mPtr = fromInt(inVal);
}

namespace
{
bool is_negative_zero(double d)
{
return d == 0.0 && std::signbit(d);
}
}

Dynamic::Dynamic(double inVal)
{
if ( (int)inVal==inVal && inVal>=-1 && inVal<256 )
if ( (int)inVal==inVal && inVal>=-1 && inVal<256 && !is_negative_zero(inVal) )
{
int idx = inVal+1;
mPtr = sConstDynamicInts[idx].mPtr;
Expand Down
16 changes: 16 additions & 0 deletions test/haxe/TestTypes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ class TestTypes extends Test
Assert.equals(d.i6, 1);
Assert.equals(d.i7, 1);
}

static function inverse(f:Dynamic)
{
return 1 / (f:Float);
}

public function testDynamicFloatZeros()
{
var positive:Dynamic = 0.0;
Assert.equals(0.0, positive);
Assert.equals(Math.POSITIVE_INFINITY, inverse(positive));

var negative:Dynamic = -0.0;
Assert.equals(-0.0, negative);
Assert.equals(Math.NEGATIVE_INFINITY, inverse(negative));
}
}