@@ -110,6 +110,16 @@ assert compare(nan, nan) == 0
110110assert compare(1.0f, nan) > 0
111111assert compare(nan, 1.0f) < 0
112112
113+ // isFinite
114+ assert Float32.isFinite(NaNf) == false
115+ assert Float32.isFinite(Infinityf) == false
116+ assert Float32.isFinite(-Infinityf) == false
117+ assert Float32.isFinite(1.0f)
118+ assert Float32.isFinite(0.0f)
119+ assert Float32.isFinite(-1.0f)
120+ assert Float32.isFinite(25.76f)
121+ assert Float32.isFinite(-25.00f)
122+
113123// isNaN
114124assert Float32.isNaN(NaNf)
115125assert Float32.isNaN(1.0f) == false
@@ -205,3 +215,221 @@ assert Float32.isNaN(Float32.copySign(NaNf, 1.0f))
205215assert Float32.isNaN(Float32.copySign(NaNf, -1.0f))
206216assert Float32.copySign(1.0f, NaNf) == 1.0f
207217assert Float32.copySign(1.0f, -NaNf) == -1.0f
218+
219+ // Float32.isClose
220+ assert Float32.isClose(1.0f, 1.0f)
221+ assert Float32.isClose(
222+ 1.0f,
223+ 1.0f,
224+ relativeTolerance=0.5f,
225+ absoluteTolerance=0.5f
226+ )
227+ assert Float32.isClose(
228+ 1.0f,
229+ 1.0f,
230+ relativeTolerance=0.0f,
231+ absoluteTolerance=0.0f
232+ )
233+ assert Float32.isClose(0.0f, 0.0f)
234+ assert Float32.isClose(
235+ 0.0f,
236+ 0.0f,
237+ relativeTolerance=0.5f,
238+ absoluteTolerance=0.5f
239+ )
240+ assert Float32.isClose(
241+ 0.0f,
242+ 0.0f,
243+ relativeTolerance=0.0f,
244+ absoluteTolerance=0.0f
245+ )
246+ assert Float32.isClose(0.0f, 0.1f) == false
247+ assert Float32.isClose(0.0f, 0.000000001f) == false
248+ assert Float32.isClose(0.0f, 0.00000001f, absoluteTolerance=1e-9f) == false
249+ assert Float32.isClose(0.0f, 0.000000001f, absoluteTolerance=1e-9f)
250+ assert Float32.isClose(-0.0f, 0.000000001f) == false
251+ assert Float32.isClose(-0.0f, 0.00000001f, absoluteTolerance=1e-9f) == false
252+ assert Float32.isClose(-0.0f, 0.000000001f, absoluteTolerance=1e-9f)
253+ assert Float32.isClose(1.1f, 1.1000001f, absoluteTolerance=1e-10f) == false
254+ assert Float32.isClose(1.1f, 1.100000001f, absoluteTolerance=1e-9f)
255+ assert Float32.isClose(Infinityf, Infinityf)
256+ assert Float32.isClose(-Infinityf, -Infinityf)
257+ assert Float32.isClose(Infinityf, -Infinityf) == false
258+ assert Float32.isClose(NaNf, NaNf) == false
259+
260+ // Float32.sin - 0 to pi/2
261+ assert Float32.sin(0.0f) == 0.0f
262+ assert Float32.isClose(Float32.sin(Float32.pi / 6.0f), 0.5f)
263+ assert Float32.isClose(
264+ Float32.sin(Float32.pi / 4.0f),
265+ Float32.sqrt(2.0f) / 2.0f
266+ )
267+ assert Float32.isClose(
268+ Float32.sin(Float32.pi / 3.0f),
269+ Float32.sqrt(3.0f) / 2.0f,
270+ absoluteTolerance=1e-5f
271+ )
272+ assert Float32.isClose(Float32.sin(Float32.pi / 2.0f), 1.0f)
273+ // Float32.sin - pi/2 to 2pi
274+ assert Float32.isClose(
275+ Float32.sin(2.0f * Float32.pi / 3.0f),
276+ Float32.sqrt(3.0f) / 2.0f
277+ )
278+ assert Float32.isClose(
279+ Float32.sin(3.0f * Float32.pi / 4.0f),
280+ Float32.sqrt(2.0f) / 2.0f
281+ )
282+ assert Float32.isClose(
283+ Float32.sin(5.0f * Float32.pi / 6.0f),
284+ 0.5f,
285+ absoluteTolerance=1e-5f
286+ )
287+ // Note: This has an absolute error of 1e-15 because `Float32.pi` is not exact
288+ assert Float32.isClose(Float32.sin(Float32.pi), 0.0f, absoluteTolerance=1e-6f)
289+ // Float32.sin - 2pi to 3pi/2
290+ assert Float32.isClose(
291+ Float32.sin(7.0f * Float32.pi / 6.0f),
292+ -0.5f,
293+ absoluteTolerance=1e-5f
294+ )
295+ assert Float32.isClose(
296+ Float32.sin(5.0f * Float32.pi / 4.0f),
297+ Float32.sqrt(2.0f) / -2.0f,
298+ absoluteTolerance=1e-5f
299+ )
300+ assert Float32.isClose(
301+ Float32.sin(4.0f * Float32.pi / 3.0f),
302+ Float32.sqrt(3.0f) / -2.0f,
303+ absoluteTolerance=1e-5f
304+ )
305+ assert Float32.isClose(Float32.sin(3.0f * Float32.pi / 2.0f), -1.0f)
306+ // Float32.sin - 3pi/2 to 0
307+ assert Float32.isClose(
308+ Float32.sin(5.0f * Float32.pi / 3.0f),
309+ Float32.sqrt(3.0f) / -2.0f,
310+ absoluteTolerance=1e-5f
311+ )
312+ assert Float32.isClose(
313+ Float32.sin(7.0f * Float32.pi / 4.0f),
314+ Float32.sqrt(2.0f) / -2.0f,
315+ absoluteTolerance=1e-5f
316+ )
317+ assert Float32.isClose(
318+ Float32.sin(11.0f * Float32.pi / 6.0f),
319+ -0.5f,
320+ absoluteTolerance=1e-5f
321+ )
322+ // Note: This has an absolute error of 1e-5 because `Float32.pi` is not exact
323+ assert Float32.isClose(
324+ Float32.sin(2.0f * Float32.pi),
325+ 0.0f,
326+ absoluteTolerance=1e-5f
327+ )
328+ // Float32.sin - special cases
329+ assert Float32.sin(0.5f) == Float32.sin(0.5f)
330+ assert Float32.sin(0.25f) == Float32.sin(0.25f)
331+ assert Float32.isNaN(Float32.sin(Infinityf))
332+ assert Float32.isNaN(Float32.sin(-Infinityf))
333+ assert Float32.isNaN(Float32.sin(NaNf))
334+
335+ // Float32.cos - 0 to pi/2
336+ assert Float32.cos(0.0f) == 1.0f
337+ assert Float32.isClose(
338+ Float32.cos(Float32.pi / 6.0f),
339+ Float32.sqrt(3.0f) / 2.0f
340+ )
341+ assert Float32.isClose(
342+ Float32.cos(Float32.pi / 4.0f),
343+ Float32.sqrt(2.0f) / 2.0f
344+ )
345+ assert Float32.isClose(
346+ Float32.cos(Float32.pi / 3.0f),
347+ 0.5f,
348+ absoluteTolerance=1e-5f
349+ )
350+ // Note: This has an absolute error of 1e-5 because `Float32.pi` is not exact
351+ assert Float32.isClose(
352+ Float32.cos(Float32.pi / 2.0f),
353+ 0.0f,
354+ absoluteTolerance=1e-5f
355+ )
356+ // Float32.cos - pi/2 to 2pi
357+ assert Float32.isClose(
358+ Float32.cos(2.0f * Float32.pi / 3.0f),
359+ -0.5f,
360+ absoluteTolerance=1e-5f
361+ )
362+ assert Float32.isClose(
363+ Float32.cos(3.0f * Float32.pi / 4.0f),
364+ Float32.sqrt(2.0f) / -2.0f
365+ )
366+ assert Float32.isClose(
367+ Float32.cos(5.0f * Float32.pi / 6.0f),
368+ Float32.sqrt(3.0f) / -2.0f,
369+ absoluteTolerance=1e-5f
370+ )
371+ assert Float32.isClose(Float32.cos(Float32.pi), -1.0f)
372+ // Float32.cos - 2pi to 3pi/2
373+ assert Float32.isClose(
374+ Float32.cos(7.0f * Float32.pi / 6.0f),
375+ Float32.sqrt(3.0f) / -2.0f,
376+ absoluteTolerance=1e-5f
377+ )
378+ assert Float32.isClose(
379+ Float32.cos(5.0f * Float32.pi / 4.0f),
380+ Float32.sqrt(2.0f) / -2.0f,
381+ absoluteTolerance=1e-5f
382+ )
383+ assert Float32.isClose(
384+ Float32.cos(4.0f * Float32.pi / 3.0f),
385+ -0.5f,
386+ absoluteTolerance=1e-5f
387+ )
388+ // Note: This has an absolute error of 1e-5 because `Float32.pi` is not exact
389+ assert Float32.isClose(
390+ Float32.cos(3.0f * Float32.pi / 2.0f),
391+ 0.0f,
392+ absoluteTolerance=1e-5f
393+ )
394+ // Float32.cos - 3pi/2 to 0
395+ assert Float32.isClose(
396+ Float32.cos(5.0f * Float32.pi / 3.0f),
397+ 0.5f,
398+ absoluteTolerance=1e-5f
399+ )
400+ assert Float32.isClose(
401+ Float32.cos(7.0f * Float32.pi / 4.0f),
402+ Float32.sqrt(2.0f) / 2.0f,
403+ absoluteTolerance=1e-5f
404+ )
405+ assert Float32.isClose(
406+ Float32.cos(11.0f * Float32.pi / 6.0f),
407+ Float32.sqrt(3.0f) / 2.0f,
408+ absoluteTolerance=1e-5f
409+ )
410+ assert Float32.isClose(Float32.cos(2.0f * Float32.pi), 1.0f)
411+ // Float32.cos - special cases
412+ assert Float32.cos(0.5f) == Float32.cos(0.5f)
413+ assert Float32.cos(0.25f) == Float32.cos(0.25f)
414+ assert Float32.isNaN(Float32.cos(Infinityf))
415+ assert Float32.isNaN(Float32.cos(-Infinityf))
416+ assert Float32.isNaN(Float32.cos(NaNf))
417+
418+ // Float32.tan - base cases
419+ assert Float32.tan(0.0f) == 0.0f
420+ assert Float32.isClose(
421+ Float32.tan(Float32.pi / 6.0f),
422+ 1.0f / Float32.sqrt(3.0f)
423+ )
424+ assert Float32.isClose(Float32.tan(Float32.pi / 4.0f), 1.0f)
425+ assert Float32.isClose(
426+ Float32.tan(Float32.pi / 3.0f),
427+ Float32.sqrt(3.0f),
428+ absoluteTolerance=1e-5f
429+ )
430+ // Float32.tan - special cases
431+ assert Float32.tan(0.5f) == Float32.tan(0.5f)
432+ assert Float32.tan(0.25f) == Float32.tan(0.25f)
433+ assert Float32.isNaN(Float32.tan(Infinityf))
434+ assert Float32.isNaN(Float32.tan(-Infinityf))
435+ assert Float32.isNaN(Float32.tan(NaNf))
0 commit comments