Commit beff36b
committed
fix(cci,correl,willr): divide by the value the guard tests, and make %R's range a guarantee (#395)
The three remaining functions carrying #390's shape: a guard that establishes one
expression while the arithmetic below it divides by another. All three are
reachable through the shipped batch API and all three return a wrong answer under
TA_SUCCESS.
CCI guards `tempReal2` and divided by `0.015*tempReal2`. The band is RELATIVE and
the underflow is ABSOLUTE, so they cross: below |average| ~ 1.6e-308 the guard
still answers "not flat" while the scaled copy is exactly 0.0. Dividing by the
deviation and scaling after removes the mismatch structurally. It also fixes the
silent half, which is larger than the loud one -- the pre-scaled form loses
precision long before it reaches Inf, measured relative error 7.7e-08 at price
scale 1e-314 rising to 4.8e-01 at 1e-321, against 2e-16 for the new form at every
one of those magnitudes.
CORREL guards ssX and ssY separately -- correctly, and correl.c explains why -- and
divided by `sqrt(ssX*ssY)`. The product carries the fourth power of the window
spread, so it leaves the double range at both ends while both factors are still
ordinary normals with all 53 bits, and no test of the factors can see it. Where
spXY is zero the result is NaN, which the [-1,1] clamp does not catch (`NaN > 1.0`
is false); where it is not, the +-Inf is rewritten to exactly +-1.0, a perfect
correlation reported from a degenerate window. A root of each factor cannot do
either: sqrt maps any finite positive double into [2.3e-162, 1.4e154], so their
product is representable at both ends. That also deletes the comment block arguing
for the one-root form, whose overflow reasoning the tree's own oracle
(ta_test_reference.c) already contradicted.
WILLR is two defects, and the maintainer's ruling on the second is on #395. It
still carried the exact `diff != 0.0` that #107 replaced in STOCH, so a
machine-flat window divided sub-epsilon residue into full-scale noise, and a
denormal range underflowed `diff` to 0.0 and answered 0 -- the value meaning a
close at the period HIGH -- for a close sitting on the period LOW. Separately, the
pre-scaled divisor cost the endpoint exactness that keeps %R in its documented
range: the shipped library returns -100.00000000000001 on the reference series at
periods 2, 3 and 4. Dividing by the range and scaling after makes the bound a
theorem for well-formed input (fl(h-c) <= fl(h-l) by monotonicity, so the quotient
is in [0,1] under every rounding mode); the clamp extends it to input TA-Lib does
not validate, a close outside its own bar. `diff` leaves the body and the
streaming handle of all four backends.
Not scoped here, and checked rather than assumed: an exhaustive scan of every
division in ta_codegen/input finds no fourth instance of the shape. The Hilbert
family matches it lexically and is cleared -- `atan(Im/Re)*rad2Deg` can only reach
+-Inf, which the `[0.67*prev, 1.5*prev]` then `[6,50]` clamp absorbs on the next
statement -- so #396's seven rows are rewritten from "reachability unproven" to
that clearance.
The sweep from #396 now has no live instance to point at, so its self-test
reconstructs CCI's pre-#395 divisor instead of reading a shipped defect, and pins
the third half the other arms pin: silent when nothing bounds an operand.
Two soundness fixes on the arm: its whole-divisor test accepted any operator, and
its equality arm lacked the exclusivity its siblings carry. CORREL's fixed divisor
is annotated rather than special-cased, which makes reverting correl.c:236 fail
twice -- the key goes stale and the new divisor arrives unannotated.
Measured, not assumed. LEGACY_TOL instrumented to record every function in one
run: CCI 1.42e-14 and WILLR 7.11e-15 are new rows at 5e-14 and 3e-14; CORREL's
3.15e-13 is unchanged, so its #242 row stands. --fuzz-064 gives WILLR its own
5e-14 absolute bound rather than leaving it in the FMA bucket, whose 1e-9 is five
orders looser than it needs -- the reason #338 gives for naming ATR. Absolute
because %R is a bounded dimensionless oscillator: its floor is a ULP of 100 at any
input magnitude.
Six new legs, each sabotage-proven against a build of the pre-fix arithmetic:
CCI subnormal (was +-Inf, now exactly +-1/0.015 -- period 2 makes the mean
deviation equal the numerator, so the expectation is an equality); CORREL at
2^-283 (was NaN, -1, +1; now 0 and +-1/sqrt(15)); and WILLR's endpoint, range,
denormal window, clamp domain (was +-10000) and machine-flat window.
Green: full C suite, generator cargo test and clippy -D warnings, Rust
clippy/doc/doctests/tests, --codegen against the frozen oracle (161 passed 0 failed
in each of the four backends, CCI and WILLR both value-compared), --xlang-hash
(338,957 golden cases, four backends bit-identical), --fuzz-064 (0 failures),
regen-check, and the four source/lock/retcode/candle checks.
Shipped-build A/B on a Zen 4 laptop, min of 12 alternating rounds x 200 reps,
20k bars, four untouched controls inside +-2%: WILLR batch 0.917 (the batch tier
LOSES a division), WILLR streaming 1.054, CCI 1.115, CORREL 1.142. The streaming
+5% is the ALT1 tier paying per bar for a hoist it used to amortise, the same
order as KAMA's clamp in #390. CCI's and CORREL's costs are one extra divide and
one extra sqrt per bar; both were checked for a cheaper correct form and neither
has one that does not reintroduce an overflow band or retighten a guard #253
deliberately widened. CORREL's is well under the ~25% the deleted comment claimed.
Closes #395.
Claude-Session: https://claude.ai/code/session_01GesMuivQUwX4xHr4hEtnS81 parent 55190f6 commit beff36b
29 files changed
Lines changed: 1484 additions & 875 deletions
File tree
- src
- ta_func
- tools/ta_regtest
- ta_test_func
- ta_codegen
- generator/tests
- input
- cci
- correl
- willr
- output
- csharp/library/src
- c/tools
- java
- fragments
- library/src/main/java/io/github/talib
- tools
- rust/library/src/ta_func
- website/src/functions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| 119 | + | |
| 120 | + | |
119 | 121 | | |
120 | 122 | | |
121 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
70 | 73 | | |
71 | 74 | | |
72 | 75 | | |
| |||
203 | 206 | | |
204 | 207 | | |
205 | 208 | | |
206 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
207 | 216 | | |
208 | 217 | | |
209 | 218 | | |
| |||
215 | 224 | | |
216 | 225 | | |
217 | 226 | | |
218 | | - | |
| 227 | + | |
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
| |||
335 | 344 | | |
336 | 345 | | |
337 | 346 | | |
338 | | - | |
| 347 | + | |
339 | 348 | | |
340 | 349 | | |
341 | 350 | | |
| |||
403 | 412 | | |
404 | 413 | | |
405 | 414 | | |
406 | | - | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
407 | 422 | | |
408 | 423 | | |
409 | 424 | | |
| |||
415 | 430 | | |
416 | 431 | | |
417 | 432 | | |
418 | | - | |
| 433 | + | |
419 | 434 | | |
420 | 435 | | |
421 | 436 | | |
| |||
547 | 562 | | |
548 | 563 | | |
549 | 564 | | |
550 | | - | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
551 | 572 | | |
552 | 573 | | |
553 | 574 | | |
| |||
559 | 580 | | |
560 | 581 | | |
561 | 582 | | |
562 | | - | |
| 583 | + | |
563 | 584 | | |
564 | 585 | | |
565 | 586 | | |
| |||
683 | 704 | | |
684 | 705 | | |
685 | 706 | | |
686 | | - | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
687 | 714 | | |
688 | 715 | | |
689 | 716 | | |
| |||
695 | 722 | | |
696 | 723 | | |
697 | 724 | | |
698 | | - | |
| 725 | + | |
699 | 726 | | |
700 | 727 | | |
701 | 728 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | | - | |
| 55 | + | |
55 | 56 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
62 | 68 | | |
63 | 69 | | |
64 | 70 | | |
| |||
295 | 301 | | |
296 | 302 | | |
297 | 303 | | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
313 | 307 | | |
314 | 308 | | |
315 | 309 | | |
316 | | - | |
| 310 | + | |
317 | 311 | | |
318 | 312 | | |
319 | 313 | | |
| |||
490 | 484 | | |
491 | 485 | | |
492 | 486 | | |
493 | | - | |
| 487 | + | |
494 | 488 | | |
495 | 489 | | |
496 | 490 | | |
| |||
701 | 695 | | |
702 | 696 | | |
703 | 697 | | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
719 | 701 | | |
720 | 702 | | |
721 | 703 | | |
722 | | - | |
| 704 | + | |
723 | 705 | | |
724 | 706 | | |
725 | 707 | | |
| |||
973 | 955 | | |
974 | 956 | | |
975 | 957 | | |
976 | | - | |
977 | | - | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
991 | 961 | | |
992 | 962 | | |
993 | 963 | | |
994 | | - | |
| 964 | + | |
995 | 965 | | |
996 | 966 | | |
997 | 967 | | |
| |||
1276 | 1246 | | |
1277 | 1247 | | |
1278 | 1248 | | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
1294 | 1252 | | |
1295 | 1253 | | |
1296 | 1254 | | |
1297 | | - | |
| 1255 | + | |
1298 | 1256 | | |
1299 | 1257 | | |
1300 | 1258 | | |
| |||
0 commit comments