1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Correctly rounded F64 elementary functions on tensors.
use crateDType;
use crateResult;
use crate;
use crateRuntime;
use crateTensor;
/// Elementwise F64 elementary functions correctly rounded to nearest, ties to even.
///
/// Each method maps one function of [`crate::algorithm::correctly_rounded`] over the elements.
///
/// - Input is F64 on the client device, in any layout. Output is a fresh contiguous F64
/// tensor of the same shape. An empty input gives an empty output.
/// - `cr_exp`, `cr_log` and `cr_log1p`: each element is the infinitely precise result
/// rounded to nearest, ties to even, with gradual underflow. Overflow gives `+inf`.
/// - `cr_acos`: each element is the infinitely precise result rounded to nearest, ties to
/// even. No result is subnormal. Correct rounding on `[-1, -2^-4]` and `[2^-4, 1]` is
/// proven by CORE-MATH's exhaustive search. For `|a| < 2^-4` no proof covers it, and
/// MPFR tests find no misrounded input.
/// - `cr_pow_scalar`: the same for every input pair whose final 256-bit rounding test
/// succeeds. CORE-MATH proves correct rounding of `pow` modulo the hardest-to-round
/// cases, which are unknown for binary64. No known input fails the test. If one does,
/// the element is the 256-bit approximation rounded to nearest.
/// - Every runtime that implements the trait returns identical bits for identical input
/// bits. The host functions return the same bits. The bits do not depend on the tensor
/// length, layout, thread count or platform libm.
/// - Every NaN result is the canonical quiet NaN `0x7ff8000000000000`. No input NaN
/// payload survives. IEEE exception flags are not promised.
///
/// The runtime must declare [`crate::runtime::FloatArithmeticContract::Ieee754Basic`] and
/// [`crate::runtime::FusedMulAddContract::Ieee754Fused`] for F64. The caller keeps
/// round-to-nearest-even and gradual underflow active. The op does not detect or change
/// that environment.
///
/// The trait sits outside [`crate::ops::TensorOps`], so an external runtime need not
/// implement it. An implementation calls [`require_correctly_rounded_contracts`] first.
///
/// # Errors
///
/// - [`crate::error::Error::UnsupportedDType`] for any dtype other than F64.
/// - [`crate::error::Error::DeviceMismatch`] for a tensor on another device.
/// - The [`require_correctly_rounded_contracts`] errors when a contract is missing.
/// - [`crate::error::Error::BackendLimitation`] on a runtime that computes no F64, such as
/// WebGPU.
/// Reject a runtime that lacks the F64 arithmetic contracts [`CorrectlyRoundedOps`] needs.
///
/// # Errors
///
/// - [`crate::error::Error::BackendLimitation`] naming `op` when the runtime does not
/// declare [`crate::runtime::FloatArithmeticContract::Ieee754Basic`] for F64.
/// - [`crate::error::Error::InvalidArgument`] naming `op` when the runtime does not
/// declare [`crate::runtime::FusedMulAddContract::Ieee754Fused`] for F64.