Skip to content

Commit 127dec1

Browse files
committed
Address review suggestions
Will squash with previous commit for PR merge if all changes are agreed on.
1 parent 31351c2 commit 127dec1

8 files changed

Lines changed: 140 additions & 155 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ members = [
2525
"macros",
2626
"python",
2727
"rational",
28-
"fuzz",
2928
]
30-
exclude = ["benchmark"]
29+
exclude = ["benchmark", "fuzz"]
3130
default-members = ["base", "integer", "float", "rational", "macros"]
3231

3332
[features]

float/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ zeroize = { optional = true, version = "1.5.7", default-features = false }
4747
diesel_v1 = { optional = true, version = "1.4.0", package = "diesel", default-features = false, features = ["postgres"]}
4848
diesel_v2 = { optional = true, version = "2.0.0", package = "diesel", default-features = false, features = ["postgres_backend"]}
4949
_bytes = { optional = true, version = "1.0", package = "bytes", default-features = false }
50+
5051
# unstable dependencies
5152
rand_v08 = { optional = true, version = "0.8.3", package = "rand", default-features = false }
5253
num-traits_v02 = { optional = true, version = "0.2.15", package = "num-traits", default-features = false }

float/src/math/consts.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ use crate::{
44
repr::{Context, Word},
55
round::{Round, Rounded},
66
};
7-
use dashu_base::{BitTest, UnsignedAbs};
8-
use dashu_int::{IBig, UBig};
7+
use core::mem::size_of;
8+
use dashu_base::{BitTest, Sign, UnsignedAbs};
9+
use dashu_int::{DoubleWord, IBig, UBig};
910

1011
impl<R: Round> Context<R> {
1112
/// Calculate π using the Chudnovsky algorithm with binary splitting.
@@ -70,19 +71,21 @@ fn chudnovsky_bs(a: usize, b: usize) -> (UBig, UBig, IBig) {
7071
if b - a == 1 {
7172
// Base case: calculate single term
7273
if a == 0 {
73-
return (UBig::ONE, UBig::ONE, IBig::from(13_591_409));
74+
return (UBig::ONE, UBig::ONE, IBig::from_parts_const(Sign::Positive, 13_591_409));
7475
}
7576

7677
let k = a as u64;
7778
let p = UBig::from(6 * k - 5) * (2 * k - 1) * (6 * k - 1);
78-
let q = UBig::from(k).pow(3) * UBig::from(10_939_058_860_032_000_u64);
79-
let t_val = IBig::from(13_591_409) + IBig::from(545_140_134_u64) * k;
79+
let q = UBig::from(k).pow(3)
80+
* if size_of::<Word>() == 2 {
81+
UBig::from(10_939_058_860_032_000_u64)
82+
} else {
83+
UBig::from_dword(10_939_058_860_032_000 as DoubleWord)
84+
};
85+
let t_val = IBig::from_parts_const(Sign::Positive, 13_591_409)
86+
+ IBig::from_parts_const(Sign::Positive, 545_140_134) * k;
8087
let t_abs = &p * t_val.unsigned_abs();
81-
let t = if a % 2 == 1 {
82-
-IBig::from(t_abs)
83-
} else {
84-
IBig::from(t_abs)
85-
};
88+
let t = IBig::from(t_abs) * Sign::from(a % 2 == 1);
8689
return (p, q, t);
8790
}
8891

float/src/math/mod.rs

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -84,68 +84,3 @@ impl<const B: Word> FpResult<B> {
8484
matches!(self, Self::Normal(_) | Self::Overflow | Self::Underflow)
8585
}
8686
}
87-
88-
/// Operations that can be performed on floating point numbers via their context.
89-
pub trait ContextOps<R: Round, const B: Word> {
90-
fn context(&self) -> &Context<R>;
91-
fn repr(&self) -> &Repr<B>;
92-
93-
/// Calculate the sine of the number.
94-
#[inline]
95-
fn sin(&self) -> FpResult<B> {
96-
self.context().sin(self.repr())
97-
}
98-
99-
/// Calculate the cosine of the number.
100-
#[inline]
101-
fn cos(&self) -> FpResult<B> {
102-
self.context().cos(self.repr())
103-
}
104-
105-
/// Calculate both the sine and cosine of the number.
106-
#[inline]
107-
fn sin_cos(&self) -> (FpResult<B>, FpResult<B>) {
108-
self.context().sin_cos(self.repr())
109-
}
110-
111-
/// Calculate the tangent of the number.
112-
#[inline]
113-
fn tan(&self) -> FpResult<B> {
114-
self.context().tan(self.repr())
115-
}
116-
117-
/// Calculate the arcsine of the number.
118-
#[inline]
119-
fn asin(&self) -> FpResult<B> {
120-
self.context().asin(self.repr())
121-
}
122-
123-
/// Calculate the arccosine of the number.
124-
#[inline]
125-
fn acos(&self) -> FpResult<B> {
126-
self.context().acos(self.repr())
127-
}
128-
129-
/// Calculate the arctangent of the number.
130-
#[inline]
131-
fn atan(&self) -> FpResult<B> {
132-
self.context().atan(self.repr())
133-
}
134-
135-
/// Calculate the 2-argument arctangent of the number (`y`) and `x`.
136-
#[inline]
137-
fn atan2(&self, x: &Repr<B>) -> FpResult<B> {
138-
self.context().atan2(self.repr(), x)
139-
}
140-
}
141-
142-
impl<R: Round, const B: Word> ContextOps<R, B> for FBig<R, B> {
143-
#[inline]
144-
fn context(&self) -> &Context<R> {
145-
&self.context
146-
}
147-
#[inline]
148-
fn repr(&self) -> &Repr<B> {
149-
&self.repr
150-
}
151-
}

0 commit comments

Comments
 (0)