Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5d98071
math: Chebyshev exp for @rs/@rd (bit-exact, faithful, range-guarded)
sigilante Jun 9, 2026
0217367
math: Chebyshev log for @rs/@rd (bit-exact, faithful, fully guarded)
sigilante Jun 10, 2026
dbba4a5
math: Chebyshev sin/cos for @rs/@rd (bit-exact, faithful, range-reduced)
sigilante Jun 10, 2026
0eab7c0
math: correctly-rounded sqrt; fix cbrt; lock derived log-2/log-10/pow
sigilante Jun 10, 2026
0184763
math: faithful atan for @rs/@rd; atan2 derives from it
sigilante Jun 10, 2026
5e6e4b0
harness: asin/acos @rd/@rs reference (fdlibm rational kernel)
sigilante Jun 10, 2026
ac6e7c9
math: faithful asin/acos for @rs/@rd (fdlibm rational kernel)
sigilante Jun 10, 2026
7369b89
math: more accurate log-2/log-10 (add integer part exactly)
sigilante Jun 10, 2026
e3937df
math: dedicated tan kernel for @rd (faithful); @rs keeps sin/cos ratio
sigilante Jun 10, 2026
0aa15b9
math: @rh (f16) transcendentals via the @rs door
sigilante Jun 10, 2026
78ab4ae
harness: f128 (@rq) layer + exp reference
sigilante Jun 10, 2026
4a247d1
tools: C/SoftFloat-f128 reference for @rq (the jet basis)
sigilante Jun 10, 2026
392bcd6
tools: add log to the @rq SoftFloat reference (exp+log faithful)
sigilante Jun 10, 2026
eb04e24
tools: extend @rq SoftFloat reference to sin/cos/sqrt
sigilante Jun 10, 2026
f0ae814
math: faithful @rq (f128) exp -- first arm of the rq port
sigilante Jun 10, 2026
2330500
math: faithful @rq log (2nd rq arm)
sigilante Jun 10, 2026
b82d791
math: faithful @rq sqrt + sin/cos (rq port continues)
sigilante Jun 10, 2026
4fffdb4
math: @rq derived fns (log-2/log-10/pow/pow-n/cbrt) + lr helper
sigilante Jun 10, 2026
1f93cc9
math: faithful @rq atan + atan2 (12/15 rq fns)
sigilante Jun 10, 2026
e3531f7
math: faithful @rq asin/acos -- @rq port complete (15/15)
sigilante Jun 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,621 changes: 1,124 additions & 497 deletions libmath/desk/lib/math.hoon

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions libmath/desk/tests/lib/math-ainv.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
:::: /tests/lib/math-ainv -- bit-exact asin/acos (PR #18).
:: fdlibm rational P/Q kernel (shared), sqrt head/tail split on [0.5,1).
:: Expected bits from libmath/tools/cheb_check.py.
::
/+ *test, math
|%
++ sad |=(x=@rd ^-(@ `@`(~(asin rd:math [%n .~1e-10]) x)))
++ cad |=(x=@rd ^-(@ `@`(~(acos rd:math [%n .~1e-10]) x)))
++ sas |=(x=@rs ^-(@ `@`(~(asin rs:math [%n .1e-5]) x)))
++ cas |=(x=@rs ^-(@ `@`(~(acos rs:math [%n .1e-5]) x)))
:: ==== @rd asin ====
++ test-asin-0 (expect-eq !>(`@`0x0) !>((sad `@rd`0x0)))
++ test-asin-half (expect-eq !>(`@`0x3fe0.c152.382d.7366) !>((sad `@rd`0x3fe0.0000.0000.0000)))
++ test-asin-1 (expect-eq !>(`@`0x3ff9.21fb.5444.2d18) !>((sad `@rd`0x3ff0.0000.0000.0000)))
++ test-asin-n1 (expect-eq !>(`@`0xbff9.21fb.5444.2d18) !>((sad `@rd`0xbff0.0000.0000.0000)))
++ test-asin-75 (expect-eq !>(`@`0x3feb.2353.15c6.80dc) !>((sad `@rd`0x3fe8.0000.0000.0000)))
++ test-asin-9 (expect-eq !>(`@`0x3ff1.ea93.705f.a172) !>((sad `@rd`0x3fec.cccc.cccc.cccd)))
++ test-asin-99 (expect-eq !>(`@`0x3ff6.de3c.6f33.d51d) !>((sad `@rd`0x3fef.ae14.7ae1.47ae)))
++ test-asin-n6 (expect-eq !>(`@`0xbfe4.978f.a326.9ee1) !>((sad `@rd`0xbfe3.3333.3333.3333)))
++ test-asin-nan (expect-eq !>(`@`0x7ff8.0000.0000.0000) !>((sad `@rd`0x7ff8.0000.0000.0000)))
++ test-asin-big (expect-eq !>(`@`0x7ff8.0000.0000.0000) !>((sad `@rd`0x3ff8.0000.0000.0000)))
:: ==== @rd acos ====
++ test-acos-0 (expect-eq !>(`@`0x3ff9.21fb.5444.2d18) !>((cad `@rd`0x0)))
++ test-acos-half (expect-eq !>(`@`0x3ff0.c152.382d.7366) !>((cad `@rd`0x3fe0.0000.0000.0000)))
++ test-acos-1 (expect-eq !>(`@`0x0) !>((cad `@rd`0x3ff0.0000.0000.0000)))
++ test-acos-n1 (expect-eq !>(`@`0x4009.21fb.5444.2d18) !>((cad `@rd`0xbff0.0000.0000.0000)))
++ test-acos-9 (expect-eq !>(`@`0x3fdc.dd9f.8f92.2e98) !>((cad `@rd`0x3fec.cccc.cccc.cccd)))
++ test-acos-n9 (expect-eq !>(`@`0x4005.8647.6251.e745) !>((cad `@rd`0xbfec.cccc.cccc.cccd)))
++ test-acos-nan (expect-eq !>(`@`0x7ff8.0000.0000.0000) !>((cad `@rd`0x7ff8.0000.0000.0000)))
:: ==== @rs ====
++ test-asin-s-half (expect-eq !>(`@`0x3f06.0a92) !>((sas `@rs`0x3f00.0000)))
++ test-asin-s-1 (expect-eq !>(`@`0x3fc9.0fdb) !>((sas `@rs`0x3f80.0000)))
++ test-asin-s-75 (expect-eq !>(`@`0x3f59.1a99) !>((sas `@rs`0x3f40.0000)))
++ test-asin-s-9 (expect-eq !>(`@`0x3f8f.549b) !>((sas `@rs`0x3f66.6666)))
++ test-asin-s-nan (expect-eq !>(`@`0x7fc0.0000) !>((sas `@rs`0x7fc0.0000)))
++ test-acos-s-0 (expect-eq !>(`@`0x3fc9.0fdb) !>((cas `@rs`0x0)))
++ test-acos-s-1 (expect-eq !>(`@`0x0) !>((cas `@rs`0x3f80.0000)))
++ test-acos-s-n1 (expect-eq !>(`@`0x4049.0fdb) !>((cas `@rs`0xbf80.0000)))
++ test-acos-s-n6 (expect-eq !>(`@`0x400d.b70d) !>((cas `@rs`0xbf19.999a)))
--
35 changes: 35 additions & 0 deletions libmath/desk/tests/lib/math-atan.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
:::: /tests/lib/math-atan -- bit-exact atan + atan2 (PR #18).
:: atan: fdlibm breakpoint reduction + minimax poly. atan2 derives from atan
:: with quadrant logic. Expected bits from libmath/tools/cheb_check.py.
::
/+ *test, math
|%
++ ad |=(x=@rd ^-(@ `@`(~(atan rd:math [%n .~1e-10]) x)))
++ as |=(x=@rs ^-(@ `@`(~(atan rs:math [%n .1e-5]) x)))
++ a2d |=([y=@rd x=@rd] ^-(@ `@`(~(atan2 rd:math [%n .~1e-10]) y x)))
:: ==== @rd ====
++ test-atan-0 (expect-eq !>(`@`0x0) !>((ad `@rd`0x0)))
++ test-atan-half (expect-eq !>(`@`0x3fdd.ac67.0561.bb4f) !>((ad `@rd`0x3fe0.0000.0000.0000)))
++ test-atan-1 (expect-eq !>(`@`0x3fe9.21fb.5444.2d18) !>((ad `@rd`0x3ff0.0000.0000.0000)))
++ test-atan-n1 (expect-eq !>(`@`0xbfe9.21fb.5444.2d18) !>((ad `@rd`0xbff0.0000.0000.0000)))
++ test-atan-1h (expect-eq !>(`@`0x3fef.730b.d281.f69b) !>((ad `@rd`0x3ff8.0000.0000.0000)))
++ test-atan-2 (expect-eq !>(`@`0x3ff1.b6e1.92eb.be44) !>((ad `@rd`0x4000.0000.0000.0000)))
++ test-atan-10 (expect-eq !>(`@`0x3ff7.89bd.2c16.0054) !>((ad `@rd`0x4024.0000.0000.0000)))
++ test-atan-tenth (expect-eq !>(`@`0x3fb9.83e2.82e2.cc4d) !>((ad `@rd`0x3fb9.9999.9999.999a)))
++ test-atan-n07 (expect-eq !>(`@`0xbfe3.8b11.2d7b.d4ad) !>((ad `@rd`0xbfe6.6666.6666.6666)))
++ test-atan-inf (expect-eq !>(`@`0x3ff9.21fb.5444.2d18) !>((ad `@rd`0x7ff0.0000.0000.0000)))
++ test-atan-ninf (expect-eq !>(`@`0xbff9.21fb.5444.2d18) !>((ad `@rd`0xfff0.0000.0000.0000)))
++ test-atan-nan (expect-eq !>(`@`0x7ff8.0000.0000.0000) !>((ad `@rd`0x7ff8.0000.0000.0000)))
++ test-atan-n0 (expect-eq !>(`@`0x8000.0000.0000.0000) !>((ad `@rd`0x8000.0000.0000.0000)))
:: ==== @rs ====
++ test-atan-s-half (expect-eq !>(`@`0x3eed.6338) !>((as `@rs`0x3f00.0000)))
++ test-atan-s-1 (expect-eq !>(`@`0x3f49.0fdb) !>((as `@rs`0x3f80.0000)))
++ test-atan-s-n1 (expect-eq !>(`@`0xbf49.0fdb) !>((as `@rs`0xbf80.0000)))
++ test-atan-s-2 (expect-eq !>(`@`0x3f8d.b70d) !>((as `@rs`0x4000.0000)))
++ test-atan-s-10 (expect-eq !>(`@`0x3fbc.4de9) !>((as `@rs`0x4120.0000)))
++ test-atan-s-inf (expect-eq !>(`@`0x3fc9.0fdb) !>((as `@rs`0x7f80.0000)))
++ test-atan-s-nan (expect-eq !>(`@`0x7fc0.0000) !>((as `@rs`0x7fc0.0000)))
:: ==== atan2 (derives from atan): quadrant + axis sanity ====
++ test-atan2-q1 (expect-eq !>(`@`0x3fe9.21fb.5444.2d18) !>((a2d `@rd`0x3ff0.0000.0000.0000 `@rd`0x3ff0.0000.0000.0000)))
++ test-atan2-yaxis (expect-eq !>(`@`0x3ff9.21fb.5444.2d18) !>((a2d `@rd`0x3ff0.0000.0000.0000 `@rd`0x0)))
--
30 changes: 30 additions & 0 deletions libmath/desk/tests/lib/math-derived.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
:::: /tests/lib/math-derived -- log-2, log-10, pow, cbrt (PR #18).
:: These derive from the now-accurate exp/log: log-2 = log/ln2, log-10 =
:: log/ln10, pow = exp(n*log x), cbrt = sign*exp(log|x|/3). They are
:: deterministic (so bit-exact-jettable via the same composition) but only
:: faithful to a few ULP (pow especially -- a notoriously hard function).
:: Expected bits from libmath/tools/cheb_check.py composing exp/log.
::
/+ *test, math
|%
++ l2d |=(x=@rd ^-(@ `@`(~(log-2 rd:math [%n .~1e-10]) x)))
++ l10d |=(x=@rd ^-(@ `@`(~(log-10 rd:math [%n .~1e-10]) x)))
++ pd |=([x=@rd n=@rd] ^-(@ `@`(~(pow rd:math [%n .~1e-10]) x n)))
++ cbd |=(x=@rd ^-(@ `@`(~(cbt rd:math [%n .~1e-10]) x)))
++ l2s |=(x=@rs ^-(@ `@`(~(log-2 rs:math [%n .1e-5]) x)))
++ l10s |=(x=@rs ^-(@ `@`(~(log-10 rs:math [%n .1e-5]) x)))
++ ps |=([x=@rs n=@rs] ^-(@ `@`(~(pow rs:math [%n .1e-5]) x n)))
++ cbs |=(x=@rs ^-(@ `@`(~(cbt rs:math [%n .1e-5]) x)))
:: ==== @rd ====
++ test-log2-8 (expect-eq !>(`@`0x4008.0000.0000.0000) !>((l2d `@rd`0x4020.0000.0000.0000)))
++ test-log10-1e3 (expect-eq !>(`@`0x4008.0000.0000.0000) !>((l10d `@rd`0x408f.4000.0000.0000)))
++ test-pow-2-half (expect-eq !>(`@`0x3ff6.a09e.667f.3bcc) !>((pd `@rd`0x4000.0000.0000.0000 `@rd`0x3fe0.0000.0000.0000)))
++ test-pow-3-2h (expect-eq !>(`@`0x402f.2d4a.4563.563f) !>((pd `@rd`0x4008.0000.0000.0000 `@rd`0x4004.0000.0000.0000)))
++ test-cbrt-27 (expect-eq !>(`@`0x4007.ffff.ffff.ffff) !>((cbd `@rd`0x403b.0000.0000.0000)))
++ test-cbrt-n8 (expect-eq !>(`@`0xbfff.ffff.ffff.ffff) !>((cbd `@rd`0xc020.0000.0000.0000)))
:: ==== @rs ====
++ test-log2-8-s (expect-eq !>(`@`0x4040.0000) !>((l2s `@rs`0x4100.0000)))
++ test-log10-1e3-s (expect-eq !>(`@`0x4040.0001) !>((l10s `@rs`0x447a.0000)))
++ test-pow-2-half-s (expect-eq !>(`@`0x3fb5.04f3) !>((ps `@rs`0x4000.0000 `@rs`0x3f00.0000)))
++ test-cbrt-n8-s (expect-eq !>(`@`0xc000.0000) !>((cbs `@rs`0xc100.0000)))
--
49 changes: 49 additions & 0 deletions libmath/desk/tests/lib/math-exp.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
:::: /tests/lib/math-exp -- bit-exact exp for the Chebyshev rewrite (PR #18).
:: Expected bit patterns are produced by libmath/tools/cheb_check.py, whose
:: strict-f64/f32 reference is bit-identical to SoftFloat for the algorithm's
:: primitives (+ - * /, round-to-int, ldexp). Covers the normal range plus
:: the NaN / +-inf / overflow / underflow / subnormal tails.
::
/+ *test, math
|%
++ es |=(x=@rs ^-(@ `@`(~(exp rs:math [%n .1e-5]) x)))
++ ed |=(x=@rd ^-(@ `@`(~(exp rd:math [%n .~1e-10]) x)))
:: ==== @rd core ====
++ test-rd-0 (expect-eq !>(`@`0x3ff0.0000.0000.0000) !>((ed `@rd`0x0)))
++ test-rd-half (expect-eq !>(`@`0x3ffa.6129.8e1e.069c) !>((ed `@rd`0x3fe0.0000.0000.0000)))
++ test-rd-1 (expect-eq !>(`@`0x4005.bf0a.8b14.576a) !>((ed `@rd`0x3ff0.0000.0000.0000)))
++ test-rd-n1 (expect-eq !>(`@`0x3fd7.8b56.362c.ef38) !>((ed `@rd`0xbff0.0000.0000.0000)))
++ test-rd-2 (expect-eq !>(`@`0x401d.8e64.b8d4.ddae) !>((ed `@rd`0x4000.0000.0000.0000)))
++ test-rd-10 (expect-eq !>(`@`0x40d5.829d.cf95.0560) !>((ed `@rd`0x4024.0000.0000.0000)))
++ test-rd-n5 (expect-eq !>(`@`0x3f7b.993f.e00d.5376) !>((ed `@rd`0xc014.0000.0000.0000)))
++ test-rd-tenth (expect-eq !>(`@`0x3ff1.aec7.b35a.00d4) !>((ed `@rd`0x3fb9.9999.9999.999a)))
:: ==== @rd edges ====
++ test-rd-pinf (expect-eq !>(`@`0x7ff0.0000.0000.0000) !>((ed `@rd`0x7ff0.0000.0000.0000)))
++ test-rd-ninf (expect-eq !>(`@`0x0) !>((ed `@rd`0xfff0.0000.0000.0000)))
++ test-rd-nan (expect-eq !>(`@`0x7ff8.0000.0000.0000) !>((ed `@rd`0x7ff8.0000.0000.0000)))
++ test-rd-big (expect-eq !>(`@`0x7fe8.1e9b.4b52.d0c9) !>((ed `@rd`0x4086.2c00.0000.0000)))
++ test-rd-ovf (expect-eq !>(`@`0x7ff0.0000.0000.0000) !>((ed `@rd`0x4086.3000.0000.0000)))
++ test-rd-ovf2 (expect-eq !>(`@`0x7ff0.0000.0000.0000) !>((ed `@rd`0x4086.8000.0000.0000)))
++ test-rd-sub (expect-eq !>(`@`0x2) !>((ed `@rd`0xc087.4000.0000.0000)))
++ test-rd-udf (expect-eq !>(`@`0x0) !>((ed `@rd`0xc087.4999.9999.999a)))
++ test-rd-udf2 (expect-eq !>(`@`0x0) !>((ed `@rd`0xc087.7000.0000.0000)))
:: ==== @rs core ====
++ test-rs-0 (expect-eq !>(`@`0x3f80.0000) !>((es `@rs`0x0)))
++ test-rs-half (expect-eq !>(`@`0x3fd3.094d) !>((es `@rs`0x3f00.0000)))
++ test-rs-1 (expect-eq !>(`@`0x402d.f854) !>((es `@rs`0x3f80.0000)))
++ test-rs-n1 (expect-eq !>(`@`0x3ebc.5ab2) !>((es `@rs`0xbf80.0000)))
++ test-rs-2 (expect-eq !>(`@`0x40ec.7326) !>((es `@rs`0x4000.0000)))
++ test-rs-10 (expect-eq !>(`@`0x46ac.14ee) !>((es `@rs`0x4120.0000)))
++ test-rs-n5 (expect-eq !>(`@`0x3bdc.c9ff) !>((es `@rs`0xc0a0.0000)))
++ test-rs-tenth (expect-eq !>(`@`0x3f8d.763e) !>((es `@rs`0x3dcc.cccd)))
:: ==== @rs edges ====
++ test-rs-pinf (expect-eq !>(`@`0x7f80.0000) !>((es `@rs`0x7f80.0000)))
++ test-rs-ninf (expect-eq !>(`@`0x0) !>((es `@rs`0xff80.0000)))
++ test-rs-nan (expect-eq !>(`@`0x7fc0.0000) !>((es `@rs`0x7fc0.0000)))
++ test-rs-big (expect-eq !>(`@`0x7ef8.82b7) !>((es `@rs`0x42b0.0000)))
++ test-rs-ovf (expect-eq !>(`@`0x7f80.0000) !>((es `@rs`0x42b2.0000)))
++ test-rs-ovf2 (expect-eq !>(`@`0x7f80.0000) !>((es `@rs`0x42c8.0000)))
++ test-rs-sub (expect-eq !>(`@`0x1) !>((es `@rs`0xc2ce.0000)))
++ test-rs-udf (expect-eq !>(`@`0x0) !>((es `@rs`0xc2d0.0000)))
++ test-rs-udf2 (expect-eq !>(`@`0x0) !>((es `@rs`0xc2dc.0000)))
--
38 changes: 38 additions & 0 deletions libmath/desk/tests/lib/math-log.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
:::: /tests/lib/math-log -- bit-exact log for the Chebyshev rewrite (PR #18).
:: Expected bit patterns from libmath/tools/cheb_check.py (strict f64/f32 ref,
:: bit-identical to SoftFloat for the primitives used). Covers the normal
:: range plus NaN / +inf / -inf / +-0 / negative / subnormal inputs.
::
/+ *test, math
|%
++ ls |=(x=@rs ^-(@ `@`(~(log rs:math [%n .1e-5]) x)))
++ ld |=(x=@rd ^-(@ `@`(~(log rd:math [%n .~1e-10]) x)))
:: ==== @rd ====
++ test-rd-1 (expect-eq !>(`@`0x0) !>((ld `@rd`0x3ff0.0000.0000.0000)))
++ test-rd-2 (expect-eq !>(`@`0x3fe6.2e42.fefa.39ef) !>((ld `@rd`0x4000.0000.0000.0000)))
++ test-rd-half (expect-eq !>(`@`0xbfe6.2e42.fefa.39ef) !>((ld `@rd`0x3fe0.0000.0000.0000)))
++ test-rd-10 (expect-eq !>(`@`0x4002.6bb1.bbb5.5516) !>((ld `@rd`0x4024.0000.0000.0000)))
++ test-rd-100 (expect-eq !>(`@`0x4012.6bb1.bbb5.5516) !>((ld `@rd`0x4059.0000.0000.0000)))
++ test-rd-tenth (expect-eq !>(`@`0xc002.6bb1.bbb5.5515) !>((ld `@rd`0x3fb9.9999.9999.999a)))
++ test-rd-e2 (expect-eq !>(`@`0x4000.0000.0000.0000) !>((ld `@rd`0x401d.8e64.b8d4.ddae)))
++ test-rd-sub (expect-eq !>(`@`0xc086.4e69.394d.9508) !>((ld `@rd`0x1268.8b70.e62b)))
++ test-rd-pinf (expect-eq !>(`@`0x7ff0.0000.0000.0000) !>((ld `@rd`0x7ff0.0000.0000.0000)))
++ test-rd-ninf (expect-eq !>(`@`0x7ff8.0000.0000.0000) !>((ld `@rd`0xfff0.0000.0000.0000)))
++ test-rd-nan (expect-eq !>(`@`0x7ff8.0000.0000.0000) !>((ld `@rd`0x7ff8.0000.0000.0000)))
++ test-rd-zero (expect-eq !>(`@`0xfff0.0000.0000.0000) !>((ld `@rd`0x0)))
++ test-rd-neg (expect-eq !>(`@`0x7ff8.0000.0000.0000) !>((ld `@rd`0xbff0.0000.0000.0000)))
:: ==== @rs ====
++ test-rs-1 (expect-eq !>(`@`0x0) !>((ls `@rs`0x3f80.0000)))
++ test-rs-2 (expect-eq !>(`@`0x3f31.7218) !>((ls `@rs`0x4000.0000)))
++ test-rs-half (expect-eq !>(`@`0xbf31.7218) !>((ls `@rs`0x3f00.0000)))
++ test-rs-10 (expect-eq !>(`@`0x4013.5d8e) !>((ls `@rs`0x4120.0000)))
++ test-rs-100 (expect-eq !>(`@`0x4093.5d8e) !>((ls `@rs`0x42c8.0000)))
++ test-rs-tenth (expect-eq !>(`@`0xc013.5d8e) !>((ls `@rs`0x3dcc.cccd)))
++ test-rs-e2 (expect-eq !>(`@`0x4000.0000) !>((ls `@rs`0x40ec.7326)))
++ test-rs-sub (expect-eq !>(`@`0xc2b8.34f2) !>((ls `@rs`0x1.16c2)))
++ test-rs-pinf (expect-eq !>(`@`0x7f80.0000) !>((ls `@rs`0x7f80.0000)))
++ test-rs-ninf (expect-eq !>(`@`0x7fc0.0000) !>((ls `@rs`0xff80.0000)))
++ test-rs-nan (expect-eq !>(`@`0x7fc0.0000) !>((ls `@rs`0x7fc0.0000)))
++ test-rs-zero (expect-eq !>(`@`0xff80.0000) !>((ls `@rs`0x0)))
++ test-rs-neg (expect-eq !>(`@`0x7fc0.0000) !>((ls `@rs`0xbf80.0000)))
--
41 changes: 41 additions & 0 deletions libmath/desk/tests/lib/math-rh.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
:::: /tests/lib/math-rh -- @rh (f16) transcendentals via the @rs door (PR #18).
:: Each @rh function widens to f32, runs the (faithful) @rs kernel, and rounds
:: the result to f16 -- correctly-rounded, since an f32 result is ~2^13 finer
:: than an f16 ULP. Expected = numpy float16 of the true value.
::
/+ *test, math
|%
++ eh |=(x=@rh ^-(@ `@`(~(exp rh:math [%n .~~1e-2]) x)))
++ lh |=(x=@rh ^-(@ `@`(~(log rh:math [%n .~~1e-2]) x)))
++ sh |=(x=@rh ^-(@ `@`(~(sin rh:math [%n .~~1e-2]) x)))
++ ch |=(x=@rh ^-(@ `@`(~(cos rh:math [%n .~~1e-2]) x)))
++ th |=(x=@rh ^-(@ `@`(~(tan rh:math [%n .~~1e-2]) x)))
++ ath |=(x=@rh ^-(@ `@`(~(atan rh:math [%n .~~1e-2]) x)))
++ ash |=(x=@rh ^-(@ `@`(~(asin rh:math [%n .~~1e-2]) x)))
++ ach |=(x=@rh ^-(@ `@`(~(acos rh:math [%n .~~1e-2]) x)))
++ qh |=(x=@rh ^-(@ `@`(~(sqt rh:math [%n .~~1e-2]) x)))
++ cbh |=(x=@rh ^-(@ `@`(~(cbt rh:math [%n .~~1e-2]) x)))
++ l2h |=(x=@rh ^-(@ `@`(~(log-2 rh:math [%n .~~1e-2]) x)))
++ l10h |=(x=@rh ^-(@ `@`(~(log-10 rh:math [%n .~~1e-2]) x)))
++ ph |=([x=@rh n=@rh] ^-(@ `@`(~(pow rh:math [%n .~~1e-2]) x n)))
++ test-exp-half (expect-eq !>(`@`0x3e98) !>((eh `@rh`0x3800)))
++ test-exp-1 (expect-eq !>(`@`0x4170) !>((eh `@rh`0x3c00)))
++ test-exp-n2 (expect-eq !>(`@`0x3055) !>((eh `@rh`0xc000)))
++ test-exp-inf (expect-eq !>(`@`0x7c00) !>((eh `@rh`0x7c00)))
++ test-log-2 (expect-eq !>(`@`0x398c) !>((lh `@rh`0x4000)))
++ test-log-half (expect-eq !>(`@`0xb98c) !>((lh `@rh`0x3800)))
++ test-sin-1 (expect-eq !>(`@`0x3abb) !>((sh `@rh`0x3c00)))
++ test-sin-pi (expect-eq !>(`@`0x13ed) !>((sh `@rh`0x4248)))
++ test-cos-1 (expect-eq !>(`@`0x3853) !>((ch `@rh`0x3c00)))
++ test-tan-1 (expect-eq !>(`@`0x3e3b) !>((th `@rh`0x3c00)))
++ test-atan-1 (expect-eq !>(`@`0x3a48) !>((ath `@rh`0x3c00)))
++ test-atan-2 (expect-eq !>(`@`0x3c6e) !>((ath `@rh`0x4000)))
++ test-asin-half (expect-eq !>(`@`0x3830) !>((ash `@rh`0x3800)))
++ test-acos-half (expect-eq !>(`@`0x3c30) !>((ach `@rh`0x3800)))
++ test-sqt-2 (expect-eq !>(`@`0x3da8) !>((qh `@rh`0x4000)))
++ test-sqt-10 (expect-eq !>(`@`0x4253) !>((qh `@rh`0x4900)))
++ test-cbt-8 (expect-eq !>(`@`0x4000) !>((cbh `@rh`0x4800)))
++ test-log2-8 (expect-eq !>(`@`0x4200) !>((l2h `@rh`0x4800)))
++ test-log10-1k (expect-eq !>(`@`0x4205) !>((l10h `@rh`0x6400)))
++ test-pow-2-h (expect-eq !>(`@`0x3da8) !>((ph `@rh`0x4000 `@rh`0x3800)))
--
Loading