rv64_fp_round_trip.c (1030B)
1 /* FP rounding & conversion edges: round-to-nearest-even is the default 2 * rv64 dynamic rounding mode. Exercise int<->double conversions across 3 * sign-changes and at the precision boundary. */ 4 5 static int d2i(double x) { return (int)x; } 6 static long long d2ll(double x) { return (long long)x; } 7 static double i2d(int x) { return (double)x; } 8 static double ll2d(long long x) { return (double)x; } 9 10 int test_main(void) { 11 /* Truncation toward zero per C semantics. */ 12 if (d2i(2.7) != 2) return 1; 13 if (d2i(-2.7) != -2) return 2; 14 if (d2i(0.0) != 0) return 3; 15 16 /* Round trip through 32-bit int domain. */ 17 if (d2i(i2d(-1)) != -1) return 4; 18 if (d2i(i2d(2147483647)) != 2147483647) return 5; 19 20 /* 64-bit ints up to the 2^53 precise-double boundary. */ 21 if (d2ll(ll2d(1LL << 52)) != (1LL << 52)) return 6; 22 if (d2ll(ll2d(-(1LL << 52))) != -(1LL << 52)) return 7; 23 24 /* Mixed signaling/quiet boundary: -0.0 + 0.0 still equals 0.0. */ 25 volatile double neg_zero = -0.0; 26 if (neg_zero + 0.0 != 0.0) return 8; 27 return 42; 28 }