skoro v0.0.0

Mathematics

How the absolute error of a GPU's sine and cosine reaches the closed forms of the removable singularities and their derivatives, measured on a wgpu adapter; the error the cutoffs are designed for and how a device is admitted to it; and the conditions a cutoff and its series must meet so that single precision on the GPU agrees with double precision as it does on the CPU.

Updated 2026-11-14 · 12 min read

The problem#

The rotations’ exponential, logarithm and Jacobians, and the exponential test sphere’s log-volume, are smooth at the identity, but their closed forms divide by a power of the angle there. Each is computed, as Removable singularities has it, by a truncated series below a cutoff and by its closed form above it. The cutoffs were chosen so that the closed form just above the cutoff, its value and its first and second derivatives, agrees in single precision with double precision, and that choice was measured on the CPU. On a wgpu adapter three checks of that agreement fail: the second-order pass of the pose’s left Jacobian in the rotations’ tests, and the second-order map of the exponential sphere’s log-volume at t=0t = 0 in the core’s. Every other check passes there.

This writeup finds why, by measuring the adapter’s elementary functions, shows how their error reaches a closed form and its derivatives, states the error the design assumes of a device and how a device is admitted to it, and states the conditions a cutoff and its series must meet for single precision on the GPU to agree with double precision as closely as it does on the CPU. It decides no cutoff: as the rotations’ mathematics left them, the numbers are settled by the implementation, against measurements, under the conditions found here.

Setting#

A computed value carries an error, the difference between what single precision returns and the exact value at the same, already rounded, input. Write u=2−24≈6.0⋅10−8u = 2^{-24} \approx 6.0 \cdot 10^{-8} for single precision’s unit roundoff. A function has relative error η\eta when its computed value is f(x)(1+δ)f(x)(1 + \delta) with ∣δ∣≤η\lvert \delta \rvert \le \eta, and absolute error ε\varepsilon when it is f(x)+δf(x) + \delta with ∣δ∣≤ε\lvert \delta \rvert \le \varepsilon. The two differ only where f(x)f(x) is small, which is exactly where a removable singularity is computed: sin⁡θ≈θ\sin \theta \approx \theta near 00.

The coefficients are those of the rotations’ table, each a function of θ2\theta^2: b=sin⁡(θ/2)/θb = \sin(\theta / 2) / \theta; A=(1−cos⁡θ)/θ2A = (1 - \cos \theta) / \theta^2; B=(θ−sin⁡θ)/θ3B = (\theta - \sin \theta) / \theta^3; CC, with cot⁡(θ/2)\cot(\theta/2); and the motions’ DD and EE, whose closed forms divide by θ4\theta^4 and θ5\theta^5. The sphere’s is Λ(r)=log⁡(sin⁡r/r)\Lambda(r) = \log(\sin r / r) with r2=∣v∣2r^2 = \lvert \tangent \rvert^2, from the measures’ exponential sphere. Their derivatives are taken by the core’s passes: each primitive’s derivative is a formula (sin⁡′=cos⁡\sin' = \cos, log⁡′=1/x\log' = 1/x) evaluated at the computed values, so a pass differentiates the formula as written, never the rounding.

The adapter’s elementary functions#

Measured on an NVIDIA GeForce RTX 4070 Ti through wgpu, against double precision at the same single-precision inputs, beside burn’s Flex device on the CPU in single precision:

functioninputsCPU, singleGPU, single
sin⁡x\sin x10−7≤x<10−410^{-7} \le x < 10^{-4}relative 1.7⋅10−91.7 \cdot 10^{-9}absolute 1.9⋅10−71.9 \cdot 10^{-7}, relative up to 11
sin⁡x\sin x10−4≤x<10−210^{-4} \le x < 10^{-2}relative 5.7⋅10−85.7 \cdot 10^{-8}absolute 1.8⋅10−71.8 \cdot 10^{-7}, relative 1.5⋅10−31.5 \cdot 10^{-3}
sin⁡x\sin x10−2≤x<π10^{-2} \le x < \pirelative 5.5⋅10−85.5 \cdot 10^{-8}absolute 3.6⋅10−73.6 \cdot 10^{-7}
sin⁡x\sin x10≤x<10010 \le x < 100relative 5.0⋅10−85.0 \cdot 10^{-8}absolute 7.8⋅10−67.8 \cdot 10^{-6}
cos⁡x\cos x10−7≤x<π10^{-7} \le x < \piabsolute 3.1⋅10−83.1 \cdot 10^{-8}absolute 3.8⋅10−73.8 \cdot 10^{-7}
exp⁡x\exp x, log⁡x\log x∣x∣<1.7\lvert x \rvert < 1.7, 10−7<x<3.210^{-7} < x < 3.2relative 6.7⋅10−86.7 \cdot 10^{-8}absolute 1.5⋅10−71.5 \cdot 10^{-7} near x=1x = 1, relative below 2⋅10−72 \cdot 10^{-7} elsewhere
atan2⁡(x,1)\operatorname{atan2}(x, 1)10−7≤x<π10^{-7} \le x < \pirelative 5.6⋅10−85.6 \cdot 10^{-8}relative 1.1⋅10−71.1 \cdot 10^{-7}

The CPU’s sine is accurate relative to its value, as a library function is. The GPU’s is accurate only to an absolute εs≈4⋅10−7≈2−21\varepsilon_s \approx 4 \cdot 10^{-7} \approx 2^{-21} on [−π,π][-\pi, \pi], whatever the argument, and worse beyond, where its argument is reduced. Its cosine is likewise absolute, at εc≈4⋅10−7\varepsilon_c \approx 4 \cdot 10^{-7}, which near cos⁡x≈1\cos x \approx 1 is a relative error of a few roundings and hardly differs from the CPU’s. Its exponential, logarithm and atan2⁡\operatorname{atan2} are relative, within a few roundings. The WGSL specification promises less still for the sine and cosine, an absolute error of 2−112^{-11} on [−π,π][-\pi, \pi], and nothing outside it: a bound under which single precision agrees with double precision to 10−410^{-4} nowhere, not even in a rotation’s matrix.

How the error reaches a closed form#

Every closed form here is

f(θ)=P(θ,sin⁡θ,cos⁡θ)θk,P(θ,sin⁡θ,cos⁡θ)=O(θk),(1) f(\theta) = \frac{P\bigl(\theta, \sin \theta, \cos \theta\bigr)}{\theta^k}, \qquad P(\theta, \sin \theta, \cos \theta) = O(\theta^k), \tag{1}
(1)

with PP a polynomial whose own partial derivatives in its second and third arguments do not vanish at 00: BB has P=θ−sin⁡θP = \theta - \sin \theta and k=3k = 3, EE has P=2θ−3sin⁡θ+θcos⁡θP = 2\theta - 3 \sin \theta + \theta \cos \theta and k=5k = 5. The numerator cancels to O(θk)O(\theta^k); the error of sin⁡\sin and cos⁡\cos does not. With the computed s~=sin⁡θ+δs\tilde s = \sin \theta + \delta_s and c~=cos⁡θ+δc\tilde c = \cos \theta + \delta_c, to first order in the errors,

f~−f=∂sP δs+∂cP δcθk, \tilde f - f = \frac{\partial_s P\, \delta_s + \partial_c P\, \delta_c}{\theta^k},

so that under the GPU’s absolute errors ∣f~−f∣≤K ε θ−k\lvert \tilde f - f \rvert \le K\, \varepsilon\, \theta^{-k}, with KK bounded near 00 and ε=max⁡(εs,εc)\varepsilon = \max(\varepsilon_s, \varepsilon_c), while under the CPU’s relative ones, ∣δs∣≤u θ\lvert \delta_s \rvert \le u\, \theta and ∣δc∣≤u\lvert \delta_c \rvert \le u, the sine’s part is smaller by the factor θ\theta.

A pass computes the mm-th derivative of (1) in θ2\theta^2 as another expression of the same form, a polynomial in θ\theta, s~\tilde s and c~\tilde c over θk+2m\theta^{k + 2m}, since each derivative in θ2\theta^2 is 12θddθ\tfrac{1}{2 \theta} \tfrac{\dd}{\dd \theta} and lowers the order of the numerator’s cancellation by two. Its error is therefore

∣dmd(θ2)m(f~−f)∣≤Km ε θ−(k+2m)on the GPU,Km u θ1−(k+2m)for the sine’s part on the CPU.(2) \Bigl\lvert \tfrac{\dd^m}{\dd (\theta^2)^m} (\tilde f - f) \Bigr\rvert \le K_m\, \varepsilon\, \theta^{-(k + 2m)} \quad \text{on the GPU}, \qquad K_m\, u\, \theta^{1 - (k + 2m)} \quad \text{for the sine's part on the CPU}. \tag{2}
(2)

The GPU loses, against the CPU, the factor εs/(u θ)\varepsilon_s / (u\, \theta), about 7/θ7 / \theta, in every closed form whose numerator holds a sine, and nothing in those that hold only a cosine. The measurements bear both out. At θ2=0.1\theta^2 = 0.1, the errors of the closed forms’ second derivatives in θ2\theta^2, against double precision, are:

coefficientkkholdsCPUGPUε θ−(k+4)\varepsilon\, \theta^{-(k + 4)}
bb11sin⁡\sin1.6⋅10−61.6 \cdot 10^{-6}1.0⋅10−61.0 \cdot 10^{-6}1.3⋅10−41.3 \cdot 10^{-4}
AA22cos⁡\cos4.9⋅10−54.9 \cdot 10^{-5}7.7⋅10−57.7 \cdot 10^{-5}4⋅10−44 \cdot 10^{-4}
BB33sin⁡\sin1.3⋅10−41.3 \cdot 10^{-4}1.2⋅10−31.2 \cdot 10^{-3}1.3⋅10−31.3 \cdot 10^{-3}
CC22sin⁡\sin, cos⁡\cos of θ/2\theta / 21.9⋅10−41.9 \cdot 10^{-4}1.5⋅10−41.5 \cdot 10^{-4}4⋅10−44 \cdot 10^{-4}
DD44cos⁡\cos4.4⋅10−34.4 \cdot 10^{-3}5.0⋅10−35.0 \cdot 10^{-3}4⋅10−34 \cdot 10^{-3}
EE55sin⁡\sin, cos⁡\cos6.4⋅10−36.4 \cdot 10^{-3}4.9⋅10−24.9 \cdot 10^{-2}1.3⋅10−21.3 \cdot 10^{-2}

The last column is the scale of (2) without its constant. BB and EE, whose numerators carry a sine with a coefficient that does not cancel, lose a factor of eight to ten on the GPU, as (2) predicts at θ≈0.32\theta \approx 0.32; AA and DD, of cosines alone, do not. These are the coefficients of the pose’s Jacobian, whose second-order pass is the one that fails. A coefficient reaches a map multiplied by powers of θ\theta, which is why errors of 10−210^{-2} in EE’s second derivative are tolerable on the CPU, but the factor of ten is not, and it carries the pass past the agreement of 10−410^{-4}.

The same factor explains the sphere. Its Λ(r)=log⁡(sin⁡r/r)\Lambda(r) = \log(\sin r / r) divides a sine by rr and its series is used below r2=10−8r^2 = 10^{-8}; the check at t=0t = 0 compares the second-order map, taken from the series, with central differences of the cotangent map at single precision’s step of 10−210^{-2}, where r2=10−4r^2 = 10^{-4} and the closed form is used, and on the GPU the closed form’s derivatives there are wrong by Kmε r−(1+2m)K_m \varepsilon\, r^{-(1 + 2m)}, far beyond the check’s tolerance. On the CPU the same derivatives are smaller by the factor u r/εsu\, r / \varepsilon_s, about 10−310^{-3}. At r2=0.1r^2 = 0.1 its second derivative’s error on the GPU is 1.7⋅10−51.7 \cdot 10^{-5} against a value of 10−210^{-2}.

Maps without a cancelling numerator are not affected: a rotation’s matrix, its action, the exponential’s cos⁡(θ/2)\cos(\theta / 2), the elementary rotations of Euler angles, each carries the absolute ε\varepsilon into its value once, below 10−610^{-6}. The logarithm’s L=2atan2⁡(n,w)/nL = 2 \operatorname{atan2}(n, w) / n divides by nn the angle of a point, which the GPU computes to its relative accuracy, so it loses nothing either.

The error designed for#

The cutoffs cannot be designed for the specification’s bound. Under an absolute error of 2−112^{-11} no map of a rotation agrees with double precision to 10−410^{-4}, closed form or not, and not even a rotation’s matrix. Nor can they be designed for the one adapter measured, since other adapters, and other drivers of this one, may differ. They are designed instead for a stated bound on the absolute error of the sine and the cosine,

ε⋆=2−20≈9.5⋅10−7on [−π,π],ε⋆far=2−16≈1.5⋅10−5beyond,(3) \varepsilon_\star = 2^{-20} \approx 9.5 \cdot 10^{-7} \quad \text{on } [-\pi, \pi], \qquad \varepsilon_\star^{\text{far}} = 2^{-16} \approx 1.5 \cdot 10^{-5} \quad \text{beyond}, \tag{3}
(3)

about 2.52.5 times the error measured on [−π,π][-\pi, \pi] and twice the error measured between 1010 and 100100. The two bounds differ because only the first is amplified. A closed form evaluates its sine and cosine beyond π\pi only where θ>π\theta > \pi, where the factor θ−(k+2m)\theta^{-(k + 2m)} of (2) is below π−(k+2m)\pi^{-(k + 2m)} and amplifies nothing. There, as in a map without a cancelling numerator, the error reaches a value about once, and ε⋆far\varepsilon_\star^{\text{far}} leaves room under the agreement of 10−410^{-4}.

The sine’s and cosine’s parts of the errors in (2) are linear in ε\varepsilon, and the rest does not depend on it. At ε⋆\varepsilon_\star, then, the GPU’s errors are at most ε⋆/ε^≈2.5\varepsilon_\star / \hat\varepsilon \approx 2.5 times those measured, with ε^\hat\varepsilon the measured error. That factor, applied to the measurements, is what the conditions below are checked against. The constant KmK_m is left out of the bound, and the measurements stand in for it.

The exponential, the logarithm and atan2⁡\operatorname{atan2} need no bound of their own, because the cancelling numerators do not amplify their errors as they amplify the sine’s. A closed form’s θ=e12log⁡θ2\theta = e^{\frac12 \log \theta^2} is computed with a relative error η\eta, of a few roundings, and so is a nearby argument θ~=θ(1+η)\tilde\theta = \theta(1 + \eta). Where the numerator and the power θk\theta^k are both formed from θ~\tilde\theta, the closed form is evaluated consistently there, and its error is f′(θ)(θ~−θ)f'(\theta)(\tilde\theta - \theta), bounded near 00. Where a power is formed from the exact θ2\theta^2 instead, the numerator’s η θ\eta\, \theta is left uncancelled. Divided by θk\theta^k, it gives an error of order η θ1−k\eta\, \theta^{1 - k}. That is the order of the CPU’s own sine error, u θ1−ku\, \theta^{1-k}, larger only by the few roundings η/u\eta / u, and never by the factor ε/(u θ)\varepsilon / (u\, \theta). Either way, the design asks of them only the relative accuracy measured.

Admission. The checks that compare single precision with double precision rest on (3), so a device must show that it meets it. With XX a finite set of single-precision inputs, and the exact values taken in double precision, whose own error of 2−532^{-53} is negligible, the device is admitted when

ε^=max⁡x∈X∩[−π,π]max⁡(∣sin⁡~ x−sin⁡x∣,∣cos⁡~ x−cos⁡x∣)≤ε⋆,(4) \hat\varepsilon = \max_{x \in X \cap [-\pi, \pi]} \max\bigl(\lvert \widetilde{\sin}\, x - \sin x \rvert, \lvert \widetilde{\cos}\, x - \cos x \rvert\bigr) \le \varepsilon_\star, \tag{4}
(4)

and the same maximum over XX beyond π\pi is at most ε⋆far\varepsilon_\star^{\text{far}}. A device that is not admitted fails there. The failure names ε^\hat\varepsilon and the bound it exceeds, rather than a coefficient’s second derivative several steps later. Admission is necessary, not sufficient: ε^\hat\varepsilon is a maximum over a sample and can miss the worst input. The room between the bound and the error measured is what absorbs the inputs the sample misses, on an adapter like the one measured. XX therefore covers the arguments the closed forms and the maps evaluate, near 00 as densely as near π\pi, as the measurements above did.

Conditions on a cutoff#

The coefficient’s closed form is used above its cutoff θc\theta_c and its series below it. Two conditions decide θc\theta_c, and the first is new.

The closed form above the cutoff. Take each coefficient ff, each order m≤2m \le 2, and each map that uses ff, and let wm(θ)w_m(\theta) be the factor by which the map multiplies ff’s mm-th derivative. Then

Km ε⋆ θc−(k+2m) wm(θc)≤τ,(5) K_m\, \varepsilon_\star\, \theta_c^{-(k + 2m)}\, w_m(\theta_c) \le \tau, \tag{5}
(5)

where τ\tau is the share of the agreement of single with double precision that the coefficient may spend. The bound decreases in θc\theta_c, so a larger cutoff always meets it. By (2), it is also met on the CPU wherever it is met on the GPU.

The scaling of (2) suggests how far a cutoff holding a sine must rise for its error on the GPU at ε⋆\varepsilon_\star to be no larger than its error on the CPU at the present θc2=0.1\theta_c^2 = 0.1. The factor is (ε⋆/(u θc))1/(k+2m)(\varepsilon_\star / (u\, \theta_c))^{1 / (k + 2m)}. At m=2m = 2 it is about 1.751.75 for BB, giving θc2≈0.31\theta_c^2 \approx 0.31, and 1.551.55 for EE, giving θc2≈0.24\theta_c^2 \approx 0.24. The factor is largest where k+2mk + 2m is smallest. It is only a guide: it drops KmK_m and the CPU’s errors from sources other than the sine, and for bb, where it predicts θc2≈0.48\theta_c^2 \approx 0.48, the measurements show the GPU’s error already below the CPU’s. The measurements decide. At θ2=1\theta^2 = 1 the GPU’s errors in the second derivatives in θ2\theta^2 were 3.7⋅10−73.7 \cdot 10^{-7} for BB, 3.8⋅10−73.8 \cdot 10^{-7} for DD and 1.5⋅10−61.5 \cdot 10^{-6} for EE. Scaled to ε⋆\varepsilon_\star, they are at most 4⋅10−64 \cdot 10^{-6}, two to three orders below what the CPU reaches at the present cutoff.

The series below it. The series truncated after NN terms, with remainder RNR_N, must meet double precision’s rounding at the cutoff, in its value and its first two derivatives:

∣dmd(θ2)mRN(θc2)∣≤2−53 ∣f(θc)∣,m≤2.(6) \Bigl\lvert \tfrac{\dd^m}{\dd (\theta^2)^m} R_N(\theta_c^2) \Bigr\rvert \le 2^{-53}\, \lvert f(\theta_c) \rvert, \qquad m \le 2. \tag{6}
(6)

The series of bb, AA, BB, DD and EE are entire, with terms falling like θ2n/(2n+k)!\theta^{2n} / (2n + k)!, so every cutoff can be met with enough terms: at θ2=1\theta^2 = 1, about ten. CC’s series is that of θ2cot⁡θ2\tfrac\theta2 \cot \tfrac\theta2. It converges for θ<2π\theta < 2\pi, with terms falling by (θ/2π)2(\theta / 2\pi)^2. Λ\Lambda’s series, log⁡(sin⁡r/r)=−r26−r4180−r62835−⋯\log(\sin r / r) = -\tfrac{r^2}{6} - \tfrac{r^4}{180} - \tfrac{r^6}{2835} - \cdots, converges for r<πr < \pi, with terms falling by (r/π)2(r / \pi)^2. Either radius bounds the cutoff away from it, and the number of terms grows as the cutoff nears it. A series costs a product and a sum per term, on every device.

Every coefficient has a cutoff meeting both. For bb, AA, BB, DD and EE, θc2=1\theta_c^2 = 1 meets (5) at ε⋆\varepsilon_\star by the measurements just scaled, and (6) with about ten terms. CC, of sines and cosines of θ/2\theta / 2 with k=2k = 2, was measured no worse on the GPU than on the CPU at θ2=0.1\theta^2 = 0.1. Its series at θc2=1\theta_c^2 = 1 falls by (2π)−2≈0.025(2\pi)^{-2} \approx 0.025 a term, so it reaches double precision’s rounding in about a dozen. The sphere needs its cutoff moved furthest. Its present one, r2=10−8r^2 = 10^{-8}, leaves the closed form in use at the check’s r2=10−4r^2 = 10^{-4}, where its second derivative’s error is of the order of ε⋆ r−5≈104\varepsilon_\star\, r^{-5} \approx 10^{4}. At r2=0.1r^2 = 0.1 the error measured, 1.7⋅10−51.7 \cdot 10^{-5}, is at most 4.3⋅10−54.3 \cdot 10^{-5} at ε⋆\varepsilon_\star. That is well inside the check’s 5⋅10−35 \cdot 10^{-3}, which is relative to the larger of the value and one and so, for values this small, absolute. There the series falls by 0.1/π2≈0.010.1 / \pi^2 \approx 0.01 a term and reaches double precision’s rounding in about eight. Below such a cutoff the check’s central differences, at r2=10−4r^2 = 10^{-4}, are taken from the series, as the second-order map is.

One cutoff still serves every target, since a composite sees neither its precision nor its device. The conditions are met for the worst of them: (3) in single precision for (5), and double precision for (6). Every other target, the CPU’s in either precision and an admitted GPU’s in double, meets them a fortiori. The archive’s cutoff for single precision, θ2≈1.37\theta^2 \approx 1.37, with its series through θ8\theta^8, was of this size.

In skoro’s terms#

Nothing random or estimated changes, and no map changes its value in exact arithmetic: the series and the closed form agree, and only the point where one replaces the other moves. What changes is the computation of a composite’s value, and of its derivatives of both orders, on a target whose elementary functions have absolute error. The core’s passes inherit that error by evaluating each primitive’s derivative formula at the computed values. The checks that compare single precision with double precision, on both sides of each cutoff, hold on the GPU once two things are true: the cutoffs meet (5) at ε⋆\varepsilon_\star, and the device is admitted by (4). The bounds of (3) are a property of the target that the design assumes, stated once. They are not a tolerance of any one check.

Built on by