Repository navigation
t27b: std.math.pow(f32, ..) from libm.t27 (Zig's std/math/pow.zig); gf16.t27 passes #7823
Copy link
Copy link
Closed
Labels
Description
Part of #7746 (t27b passes specs/numeric/gf16.t27), which is part of #6063 (t27b coverage), item C10 of #6488. This is the last PR of #7746's split, after #7791, #7819 and #7822. It makes gf16.t27 pass and closes #7746.
What gf16.t27 needs
gf16_pow calls std.math.pow(f32, base_val, exp_val), and gf16_pow_two_cubed and others reach it. After #7822 it is gf16.t27's last blocker (ExprCall(std.*), call to std.math.pow).
What the reference does
std.math.pow(f32, x, y) is not compiler_rt. It is Zig 0.16's std/math/pow.zig, a port of Go's math.Pow:
- The special cases come first: y = +-0, x = 1, a NaN, y = 1, x = +-0, y = +-inf and x = +-inf.
y == 0.5is@sqrt(x).- Otherwise y is split by
math.modf(an f32@trunc). The fractional part gives@exp(yf * @log(x)), the f32expfandlogf. The integer part is a square-and-multiply onmath.frexp(x), and the result ismath.scalbn(a1, ae), which ismath.ldexp, with its own rounding of a subnormal result. isOddIntegertakes an f64 and calls the f64math.modf.- A NaN result of the special cases is
math.nan(f32), 0x7FC00000. - Measured on the t27c lab: a comptime-folded
std.math.pow(f32, ..)equals the run-time call on a 49-point grid.
Plan
- Port
powfor an f32 to t27 inspecs/tri/t27b/libm.t27, with what it calls:frexpandldexpof an f32,isOddInteger, and compiler_rt's f64trunc. It reuses the ports ofexpf,logf(t27b: f32 @log, @log2 and @log10 from libm.t27 (compiler_rt logf, log2f, log10f) #7822),truncf(t27b: f32 @floor, @ceil, @round, @trunc and @rem from libm.t27 (compiler_rt floorf, ceilf, roundf, truncf, fmodf) #7819) andnan. specs/tri/t27b/libm_plan.t27:std.math.pownames its float type and takes three operands. An f32 callspowf, and an f64 is refused.- Hold the port to
std.math.powbit for bit over grids of x and y, in a spec of its own.
Acceptance criteria
t27b test --blockers specs/numeric/gf16.t27reports nothing.t27b test specs/numeric/gf16.t27passes every test thatt27c test-reportpasses, with the same verdicts.- The lab corpus receipt compare gives IMPROVED_ONLY, EQUIVALENT or NEUTRAL.
User Scenarios
- Given the
specs/numeric/gf16.t27spec callsstd.math.pow(f32, ...)viagf16_pow, Whent27b test --blockers specs/numeric/gf16.t27is run, Then it reports no blockers forstd.math.pow. - Given the
specs/tri/t27b/libm.t27file implementspowffor f32 withfrexp,ldexp,isOddInteger, andtruncfrom compiler_rt, Whent27b test specs/numeric/gf16.t27runs, Then every test passes with the same verdicts ast27c test-report.
Requirements
- FR-001:
specs/tri/t27b/libm.t27MUST implementpowffor f32 matching Zig 0.16'sstd/math/pow.zigspecial cases and algorithm. - FR-002:
specs/tri/t27b/libm.t27MUST providefrexpandldexpfor f32,isOddIntegerusing f64modf, and use compiler_rt's f64trunc. - FR-003:
specs/tri/t27b/libm_plan.t27MUST declarestd.math.powas taking three operands (type, base, exponent), route f32 topowf, and refuse f64. - FR-004: The implementation MUST produce bit-for-bit identical results to the reference over grids of x and y values.
Boundary
- specs/numeric/gf16.t27
- specs/tri/t27b/libm.t27
- specs/tri/t27b/libm_plan.t27
Reactions are currently unavailable
Activity
Merge master into t27b/gf16-pow (Closes #7823)
Merge master into t27b/gf16-pow; no hand-written line under cli/t27b (C…
t27b: std.math.pow of an f32 calls a t27 port of Zig's pow.zig, and g…