Skip to content

[libc][math] log_eval_f uses overly precise polynomial for float16. #137190

Open
@harrisonGPU

Description

@harrisonGPU

In log_eval_f, we reuse a minimax polynomial approximation for log(1 + x)/x that was originally designed for float, even when computing with float16 values (like in atanhf16).

The current setup uses:

Range: [0, 2⁻⁷]

Polynomial degree: 6 (degree-5 after removing the constant term 1)

Its accuracy is far beyond what’s needed for half precision:

display = hexadecimal;
I = [0; 2^-7];
P = 1 + x*(-0x1p-1 + x*(0x1.555556p-2 + x*(-0x1.00022ep-2 + x*(0x1.9ea056p-3 + x*(-0x1.e50324p-2 + x*0x1.c018fp3)))));
dirtyinfnorm(log(1 + x)/x - P, I);
→ 0x1.47b67da6...p-48 ≈ 2⁻⁴⁸

This is much more precise than necessary for float16, where a relative error of about 2⁻¹² would usually be enough. It might be worth simplifying the range reduction and using a lower-degree polynomial when targeting float16.

Followup from #132612

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions