Skip to content

BUG: Correct sin/cos float64 range check functions - #23695

Merged
seberg merged 3 commits into
numpy:mainfrom
Mousius:sincos-range-checks
May 2, 2023
Merged

seberg merged 3 commits into
numpy:mainfrom
Mousius:sincos-range-checks

Conversation

@Mousius

@Mousius Mousius commented May 2, 2023

Copy link
Copy Markdown
Member

When I translated range checks for sin:

cmp = v_cond_u64 ((ir >> 52) - TinyBound >= Thresh);

and cos:

cmp = v_cond_u64 (v_as_u64_f64 (r) >= v_as_u64_f64 (RangeVal));

They ended up the wrong way around, this corrects it.

@seberg

seberg commented May 2, 2023

Copy link
Copy Markdown
Member

Could you tighten the tests to proof that this fixes things?

@Mousius
Mousius force-pushed the sincos-range-checks branch from 05ac576 to 9bbd76a Compare May 2, 2023 14:48
@Mousius

Mousius commented May 2, 2023

Copy link
Copy Markdown
Member Author

@seberg, apologies, minor panic seeing the incorrect functionality, have added a test now 😸

dtype=np.float64
)
np.sin(underflow_trigger)
np.cos(underflow_trigger)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I guess before sin always ran into it at least.

Seems mac gets the underflows wrong here. Honestly, I doubt we should bother much about underflow warnings, but its nicer to get this right for now. I suspect we are skipping/xfailing mac often enough that we can just steal that here.

Just to be sure: This is really just about the warnings and not about the values?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yip,np.sin would throw an exception here due to fenv but would otherwise be fine, the same is true for pure optimised routines:

_ZGVnN2v_sin(0x1.f37f47a03f82ap-511) is 0x1.f37f47a03f82ap-511 +0 ulp, got except 0x18 wrongly set: 0x8

I added np.cos to prove we didn't instead introduce a FloatingPointException by removing the bounding.

@seberg

seberg commented May 2, 2023

Copy link
Copy Markdown
Member

Thanks, lets hope the discussion on the original PR doesn't mean more follow-ups are necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants