This source file includes following definitions.
- h_assert
- main
#include "Halide.h"
#include <stdio.h>
#include <cmath>
using namespace Halide;
void h_assert(bool condition, const char* msg) {
if (!condition) {
printf("FAIL: %s\n", msg);
abort();
}
}
int main() {
const float16_t one("1.0", RoundingMode::ToNearestTiesToEven);
const float16_t onePointTwoFive("1.25", RoundingMode::ToNearestTiesToEven);
h_assert(one.to_bits() != onePointTwoFive.to_bits(), "bits should be different");
h_assert(one.to_bits() == 0x3c00, "bit pattern for 1.0 is wrong");
h_assert(onePointTwoFive.to_bits() == 0x3d00, "bit pattern for 1.25 is wrong");
h_assert(!(one == onePointTwoFive), "comparision failed");
h_assert(one != onePointTwoFive, "comparision failed");
h_assert(one < onePointTwoFive, "comparision failed");
h_assert(one <= onePointTwoFive, "comparision failed");
h_assert(onePointTwoFive > one, "comparision failed");
h_assert(onePointTwoFive >= one, "comparision failed");
h_assert(one >= one, "comparision failed");
h_assert(one == one, "comparision failed");
const float16_t minusOne = -one;
h_assert(minusOne < one, "-1.0 should be < 1.0");
h_assert(one > minusOne, "1.0 should be > -1.0");
const float16_t nanValue = float16_t::make_nan();
h_assert(nanValue.are_unordered(nanValue), "NaN must be unordered");
h_assert(nanValue != nanValue, "NaN must not compare equal to itself");
h_assert(!(nanValue == nanValue), "NaN must not compare equal to itself");
h_assert(nanValue.are_unordered(one), "1.0 and NaN should be unordered");
h_assert(nanValue.are_unordered(float16_t::make_zero(true)),
"+0 and NaN should be unordered");
h_assert(nanValue.are_unordered(float16_t::make_zero(false)),
"-0 and NaN should be unordered");
h_assert(nanValue.are_unordered(float16_t::make_infinity(true)),
"+inf and NaN should be unordered");
h_assert(nanValue.are_unordered(float16_t::make_infinity(false)),
"-inf and NaN should be unordered");
const float16_t zeroP = float16_t::make_zero(true);
const float16_t zeroN = float16_t::make_zero(false);
h_assert(!zeroP.are_unordered(zeroN), "+0 and -0 should be ordered");
h_assert(zeroP == zeroN, "+0 and -0 should be treated as equal");
const float16_t infinityP = float16_t::make_infinity(true);
const float16_t infinityN = float16_t::make_infinity(false);
h_assert(!infinityP.are_unordered(infinityN),"Infinities are ordered");
h_assert(infinityP > infinityN, "inf+ should be > inf-");
h_assert(infinityN < infinityP, "inf- should be < inf+");
h_assert(one < infinityP, "1.0 should be < inf+");
h_assert(minusOne < infinityP, "1.0 should be < inf+");
h_assert(one > infinityN, "1.0 should be > inf-");
h_assert(minusOne > infinityN, "-1.0 should be > inf-");
printf("Success!\n");
return 0;
}