MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / testSpecialCases

Function testSpecialCases

numeric_types/half.cpp:88–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88void testSpecialCases() {
89 half h;
90 char message[512];
91
92 // Zero
93 h.data = 0x0000;
94 snprintf(message, sizeof(message), "0x0000 correctly converted to 0.0f");
95 printResult(halfToFloat(h) == 0.0f, message, 0.0f, halfToFloat(h));
96
97 // Negative zero
98 h.data = 0x8000;
99 snprintf(message, sizeof(message), "0x8000 correctly converted to -0.0f");
100 printResult(halfToFloat(h) == -0.0f, message, -0.0f, halfToFloat(h));
101
102 // Infinity
103 h.data = 0x7c00;
104 snprintf(message, sizeof(message), "0x7c00 correctly converted to positive infinity");
105 printResult(isinf(halfToFloat(h)) && halfToFloat(h) > 0, message, INFINITY,
106 halfToFloat(h));
107
108 // Negative infinity
109 h.data = 0xfc00;
110 snprintf(message, sizeof(message), "0xfc00 correctly converted to negative infinity");
111 printResult(isinf(halfToFloat(h)) && halfToFloat(h) < 0, message, -INFINITY,
112 halfToFloat(h));
113
114 // NaN
115 h.data = 0x7e00;
116 snprintf(message, sizeof(message), "0x7e00 correctly converted to NaN");
117 printResult(isnan(halfToFloat(h)), message, NAN, halfToFloat(h));
118
119 // Smallest positive normal number
120 h.data = 0x0400;
121 snprintf(message, sizeof(message), "0x0400 correctly converted to 6.10352e-05f");
122 printResult(approximatelyEqual(halfToFloat(h), 6.10352e-05f, EPSILON),
123 message, 6.10352e-05f, halfToFloat(h));
124
125 // Largest denormalized number
126 h.data = 0x03ff;
127 snprintf(message, sizeof(message), "0x03ff correctly converted to 6.09756e-05f");
128 printResult(approximatelyEqual(halfToFloat(h), 6.09756e-05f, EPSILON),
129 message, 6.09756e-05f, halfToFloat(h));
130
131 // Smallest positive denormalized number
132 h.data = 0x0001;
133 snprintf(message, sizeof(message), "0x0001 correctly converted to 5.96046e-08f");
134 printResult(approximatelyEqual(halfToFloat(h), 5.96046e-08f, EPSILON),
135 message, 5.96046e-08f, halfToFloat(h));
136
137 // Zero
138 h = halfFromFloat(0.0f);
139 snprintf(message, sizeof(message), "0.0f correctly converted to 0x0000");
140 printResult(h.data == 0x0000, message, 0.0f, h.data);
141
142 // Negative zero
143 h = halfFromFloat(-0.0f);
144 snprintf(message, sizeof(message), "-0.0f correctly converted to 0x8000");
145 printResult(h.data == 0x8000, message, -0.0f, h.data);

Callers 1

mainFunction · 0.85

Calls 4

printResultFunction · 0.85
halfToFloatFunction · 0.85
approximatelyEqualFunction · 0.85
halfFromFloatFunction · 0.85

Tested by

no test coverage detected