Fix complex angle usage in toinf and add off-axis tests - #85
Open
PatrickHaecker wants to merge 3 commits into
Open
Fix complex angle usage in toinf and add off-axis tests#85PatrickHaecker wants to merge 3 commits into
toinf and add off-axis tests#85PatrickHaecker wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #85 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 266 266
=========================================
Hits 266 266 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PatrickHaecker
force-pushed
the
complex_angle
branch
from
September 6, 2026 04:52
efe3786 to
0314983
Compare
added 3 commits
September 6, 2026 07:01
`_sb` was short for `signbit`. The function returns a count of half turns. For a real number that count is the sign bit, which is where the old name came from. The new name says which unit the caller gets.
`ComplexInfinity` stores its direction in half turns, but `toinf` filled the field with the radian `angle(x)`. The direction of an infinite complex summand was therefore off by a factor of π: `angle(toinf(complex(0,Inf)))` gave 4.93 instead of `π/2`. `_infadd` compares those angles, so a sum whose parts point the same way threw although `==` called them equal. Both `complex(-Inf,0.0) + -∞` and `complex(0,Inf) + ComplexInfinity(0.5)` raised an ArgumentError. Only the positive real axis escaped, angle `0` being the fixed point of the missing scaling. `_halfturns` is the conversion the multiplication already uses. It moves above the addition section, because both sections use it now.
`exp(im*π/4)*∞ == Inf+im*Inf` held by coincidence. `angle(x)/π` round-trips exactly only on the axes, where `angle` returns exactly `0`, `±π/2` or `π`. Off the axes `π/4` happens to come back unchanged, while the adjacent `π/8` gives 0.12500000000000003 and a sweep of `k/2^12` misses 2000 of 8192 angles. That assertion now compares the angle with `≈`. The four axes go through one loop, which also compares the infinity with the infinite `Complex` itself. That comparison is the only test in the suite reaching `==(::AllInfinities, ::Complex)`, and on an axis it is exact. Two assertions say what a rescaling does. `angle` is scale invariant wherever the scaling itself is exact, so a direction only moves when the rescaled operand has to be rounded.
PatrickHaecker
force-pushed
the
complex_angle
branch
from
September 6, 2026 05:09
0314983 to
7d555d3
Compare
Contributor
Author
|
I updated and rebased the branch so that it fits best to the other PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The different units, half-turns and radians, are indeed incorrectly mixed in
toinfleading to an error of a factor ofπ. The only test covering this line was an angle of0…This PR fixes this and adds some off-axis tests to cover these things with the tests in the future.
Thanks for triggering the investigation with your review finding, @dlfivefifty.