Created
October 21, 2016 21:03
-
-
Save Randl/3aea2f9a406f022931a64d7ec9242a8c to your computer and use it in GitHub Desktop.
Tests for half.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "half.h" | |
#include "picotest.h" | |
TEST(arithm, half_float) { | |
half abs_error(1e-2); | |
EXPECT_EQ(half(7.2), std::abs(half(-7.2))); | |
EXPECT_EQ(half(7.2), std::abs(half(7.2))); | |
EXPECT_EQ(false, bool(half(0.0))); | |
EXPECT_NEAR(half(8.602), half(7.238)+half(1.364),abs_error); | |
EXPECT_NEAR(half(8.602), half(7.238)+half(1.364),abs_error); | |
EXPECT_NEAR(half(5.874), half(7.238)-half(1.364),abs_error); | |
EXPECT_NEAR(half(9.872632), half(7.238)*half(1.364),abs_error); | |
EXPECT_NEAR(half(5.30645), half(7.238)/half(1.364),abs_error); | |
EXPECT_EQ(5, int(half(5.0))); | |
EXPECT_EQ(false, bool(half(0.0))); | |
half x = 5.0; | |
EXPECT_NEAR(half(5.0), x,abs_error); | |
x+=1000.0; | |
EXPECT_NEAR(double(1005.0), double(x),1e-2); | |
x+=5000.0; | |
EXPECT_NEAR(double(6005.0),double(x),1); | |
x/=half(3000.0); | |
EXPECT_NEAR(double(2.002),double(x),1e-2); | |
half y(std::numeric_limits<float>::infinity()), z = half(1.0), w=half(0.0); | |
EXPECT_EQ(true, y.isInfinity()); | |
EXPECT_EQ(true, x.isFinite()); | |
EXPECT_EQ(true, w.isZero()); | |
EXPECT_EQ(false, z.isNan()); | |
z=w/w; | |
EXPECT_EQ(true, z.isNan()); | |
EXPECT_EQ(true, (-x).isNegative()); | |
EXPECT_EQ(true, half(5.0).isNormalized()); | |
EXPECT_EQ(true, half(0.00002).isDenormalized()); | |
EXPECT_EQ(0.654_h, half(0.654)); | |
} | |
int main(void) { | |
return RUN_ALL_TESTS(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment