Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Generic cbrt #516

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/libm-test/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl<F: Float, I: Int> EitherPrim<Domain<F>, Domain<I>> {
Box::new((0..u8::MAX).map(|scale| {
let mut base = F::ZERO;
for _ in 0..scale {
base = base - F::ONE;
base -= F::ONE;
}
base
}))
Expand Down
7 changes: 7 additions & 0 deletions crates/libm-test/src/f8_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ impl Float for f8 {
const NEG_PI: Self = Self::ZERO;
const FRAC_PI_2: Self = Self::ZERO;

/// `2^sig_bits`
const TWO_POW_SIG_BITS: Self =
Self(((Self::SIG_BITS + Self::EXP_BIAS) as Self::Int) << Self::SIG_BITS);
/// `2^-sig_bits`
const TWO_POW_NEG_SIG_BITS: Self =
Self(((-(Self::SIG_BITS as i32) + Self::EXP_BIAS as i32) as Self::Int) << Self::SIG_BITS);

const BITS: u32 = 8;
const SIG_BITS: u32 = 3;
const SIGN_MASK: Self::Int = 0b1_0000_000;
Expand Down
23 changes: 23 additions & 0 deletions etc/consts-cbrt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

using Printf
using Remez

function main()
run_one("f64", "hf64!", 53)
end

function run_one(name::String, hf::String, precision::Integer)
setprecision(precision)

println("Constants for ", name)

println("const ESCALE: [Self; 3] = [")
for n in 0:2
val = big(2) ^ (n / 3)
@printf " %s(\"%a\"),\n" hf val
end
print("];")

end

main()
4 changes: 4 additions & 0 deletions etc/update-api-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

# These files do not trigger a retest.
IGNORED_SOURCES = ["src/libm_helper.rs"]
# Same as above, limited to specific functions
IGNORED_SOURCES_MAP = {"fma": ["src/math/cbrt.rs"]}

IndexTy: TypeAlias = dict[str, dict[str, Any]]
"""Type of the `index` item in rustdoc's JSON output"""
Expand Down Expand Up @@ -138,6 +140,8 @@ def _init_defs(self, index: IndexTy) -> None:

for src in IGNORED_SOURCES:
sources.discard(src)
for src in IGNORED_SOURCES_MAP.get(name, []):
sources.discard(src)

# Sort the set
self.defs = {k: sorted(v) for (k, v) in defs.items()}
Expand Down
Loading