Format-generic executable sine and cosine #
Finite arguments of at least three quarters are reduced modulo pi / 2 by the Payne-Hanek window
reduction of Numerics.Enclosure.ArgumentReduction, which reads a window of the cached 2 / pi at
the cache level the argument's exponent needs. With p the destination precision, the reduction
keeps p + 32 relative bits of the remainder: it doubles its window, at most four times and only
while the window stays within the cache level trigReductionLevelLimit, until its proved error is
below 2^-(p + 32) of the remainder. When no permitted window is accepted, sine and cosine give the
format's invalid result. Multiplying the accepted remainder by the cached pi / 2 and truncating to
p + 40 significant bits gives the reduced argument. Smaller arguments are their own reduced
argument. The sine and cosine of the reduced argument are evaluated from exact common-denominator
Taylor polynomials, with as many terms as the argument's exponent needs. The quadrant and the sign
of the argument are applied to these exact values, and each result is rounded once to Model fmt.
The reduction reads at most level trigReductionLevelLimit of the cache, 2^21 bits of 2 / pi.
For an argument m * 2^e whose significand has k bits, the first window has
2 k + fracWidth + 53 bits and stays within that level when max e 0 + 2 k + fracWidth + 59 is at
most 2^21. A format argument has k ≤ fracWidth + 1, so in a format with at most 524,258
fraction bits every finite argument below 2^(2^20) qualifies, and with the conventional bias that
covers every exponent field of at most 21 bits. Arguments whose first window needs a higher level,
such as the largest ones of a 31-bit exponent field, give the format's invalid result.
For leading exponents below -(fracWidth + 2), the provider returns the input and one, preserving
tiny sine results without converting them to the fixed-point reduction scale. The reduction error is
proved (Numerics.Enclosure.ArgumentReduction.QuarterTurns.Reduces.abs_sin_sub_rotate_le), but the
truncation, the Taylor remainder and the final rounding are not, so the kernels are deterministic
approximations without a whole-algorithm accuracy or correct-rounding certificate.
Bits kept beyond the destination precision by trigonometric argument reduction.
Instances For
Window doublings allowed after the first attempt of trigonometric reduction.
Instances For
Highest level of the constants cache that trigonometric reduction reads: levelBits 15 = 2^21 bits
of 2 / pi, computed in a few seconds on first use and then cached. Each further level would take
more than twice as long. A reduction whose first window needs a higher level gives the invalid
result, and later attempts use only the doublings whose windows stay within this level
(Numerics.Enclosure.ArgumentReduction.fuelWithin?). For ieee 31 23 the first window stays within
it for every argument below 2^2097046.
Instances For
A dyadic numerator over a denominator, kept exact until its single rounding. The kernels take the
denominators from the Taylor data of their configuration, which are positive in the built-in
configurations Config.binary32 and Config.generatedWith.
- numerator : Numerics.Dyadic
The exact numerator.
- denominator : ℕ
The denominator, positive for the built-in configurations.
Instances For
Negation changes the sign of the numerator.
Round a ratio once to the destination format.
Instances For
The number of sine terms for a relative remainder below 2^-target at an argument below
2^-magnitude: the first n ≥ 1 with 2^target ≤ 2^(2 n magnitude) * (2 n + 1)!, so the first
omitted term |x|^(2n+1) / (2n+1)! is below 2^-target |x|. One term suffices once
2 magnitude ≥ target. Otherwise the search keeps that product as it goes and stops after
target steps, where (2 n + 1)! ≥ 2^(2 n) alone exceeds the target.
Instances For
The exact Taylor sums of sine and cosine at a nonzero value below one, before division by the
configuration's denominators: the first terms coefficients of config.sinCoeffsAsc and the first
terms + 1 of config.cosCoeffsAsc, or all of them when the configuration has fewer.
With |value| < 2^-s and terms = trigTaylorTerms (bits + 8) s, the first omitted terms are below
2^-(bits + 8) |value| when the configuration holds at least terms sine and terms + 1 cosine
coefficients. A shorter table omits the terms past its end instead: the pinned binary32 table has
7 sine and 7 cosine coefficients, so at |value| = pi / 4 its first omitted terms are about
2^-45 |value| for the sine and 2^-41 for the cosine.
Instances For
Reduce a positive dyadic m * 2^e modulo pi / 2, keeping bits relative bits.
Numerics.Enclosure.ArgumentReduction.reduce reduces it with windows from startWindow p bits,
with p the bit length of m, doubling at most trigReductionFuel times and only while the
window reads a cache level of at most trigReductionLevelLimit (fuelWithin?). The fraction of
the accepted reduction times the cached lower bound of pi / 2 at bits + 8 bits is truncated to
bits + 8 significant bits. Returns the quadrant and this reduced argument, or none when the
first window would read a level above the limit or no permitted window is accepted.
Instances For
Whether a positive dyadic with significand m and leading exponent leading is below 3/4.
Instances For
Sine of a nonzero dyadic of leading exponent leading < -(fracWidth + 2), with no work
proportional to its exponent.
A value representable in the format is its own nearest result: x - sin x < x^3/6 is far below
half its unit. Otherwise sin x lies strictly between x - x^3/6 and x. When x^3/6 is below
a quarter of the unit of the last bit of x, the only rounding boundary that can lie between
them is x itself, so rounding x moved a quarter unit toward zero selects the nearest
encoding of sin x, also when x is a rounding midpoint. A shorter-than-necessary unit gives
an argument with at least about 2 |leading| bits, whose sine is evaluated from every sine
coefficient of the configuration.
Instances For
Reduce a dyadic argument modulo pi / 2 and evaluate sine and cosine.
The configuration supplies the Taylor coefficients, and the reduction itself reads the constants
cache of Numerics.Enclosure.Constants. Tiny arguments use tinySine, and their cosine
1 - x^2/2 rounds to one. Other arguments below three quarters evaluate the polynomials on the
exact argument, and larger ones are reduced by reduceQuarterTurns? with
fracWidth + 1 + trigGuardBits relative bits. The polynomials take the terms that
trigTaylorTerms asks for at the exponent of the reduced argument. The quadrant and the sign of
the argument are applied before the single
rounding of each result. The format's invalid result means that the reduction would need a cache
level above trigReductionLevelLimit or that no permitted window was accepted. For an argument
m * 2^e whose significand has k bits, the first window stays within the limit when
max e 0 + 2 k + fracWidth + 59 ≤ 2^21. The results are deterministic approximations without a
numerical accuracy certificate.
Instances For
Evaluate sine and cosine with a delayed configuration provider.
The provider is called only for finite, nonzero inputs outside the tiny-argument branch. Exceptional inputs keep their ordinary encoded results: NaNs are quieted and infinities give the format's invalid result.
Instances For
Joint deterministic sine/cosine evaluation with the given approximation data.
Instances For
Deterministic sine with the given approximation data.
Instances For
Deterministic cosine with the given approximation data.
Instances For
Joint sine/cosine evaluation using the default configuration.
Instances For
Sine using the default configuration.
Instances For
Cosine using the default configuration.