Skip to content

Commit

Permalink
Improve Windows compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
benruijl committed Sep 11, 2024
1 parent 558078f commit 4daebee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
34 changes: 17 additions & 17 deletions src/domains/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,7 @@ impl NumericalFloatLike for Float {

#[inline]
fn pow(&self, e: u64) -> Self {
rug::ops::Pow::pow(&self.0, e)
.complete(self.prec() as i64)
.into()
MultiPrecisionFloat::with_val(self.prec(), rug::ops::Pow::pow(&self.0, e)).into()
}

#[inline(always)]
Expand Down Expand Up @@ -994,18 +992,19 @@ impl Real for Float {

#[inline(always)]
fn sqrt(&self) -> Self {
self.0.sqrt_ref().complete(self.prec() as i64 + 1).into()
MultiPrecisionFloat::with_val(self.prec() + 1, self.0.sqrt_ref()).into()
}

#[inline(always)]
fn log(&self) -> Self {
// Log grows in precision if the input is less than 1/e and more than e
let e = self.0.get_exp().unwrap();
if !(0..2).contains(&e) {
self.0
.ln_ref()
.complete((self.0.prec() + e.unsigned_abs().ilog2() + 1) as i64)
.into()
MultiPrecisionFloat::with_val(
self.0.prec() + e.unsigned_abs().ilog2() + 1,
self.0.ln_ref(),
)
.into()
} else {
self.0.clone().ln().into()
}
Expand All @@ -1015,10 +1014,11 @@ impl Real for Float {
fn exp(&self) -> Self {
if let Some(e) = self.0.get_exp() {
// Exp grows in precision when e < 0
self.0
.exp_ref()
.complete(1.max(self.0.prec() as i32 - e + 1) as i64)
.into()
MultiPrecisionFloat::with_val(
1.max(self.0.prec() as i32 - e + 1) as u32,
self.0.exp_ref(),
)
.into()
} else {
self.0.clone().exp().into()
}
Expand Down Expand Up @@ -1068,11 +1068,11 @@ impl Real for Float {
fn tanh(&self) -> Self {
if let Some(e) = self.0.get_exp() {
if e > 0 {
return self
.0
.tanh_ref()
.complete((self.0.prec() + 3 * e.unsigned_abs() + 1) as i64)
.into();
return MultiPrecisionFloat::with_val(
self.0.prec() + 3 * e.unsigned_abs() + 1,
self.0.tanh_ref(),
)
.into();
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/domains/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{

use rand::Rng;
use rug::{
integer::IntegerExt64,
ops::{Pow, RemRounding},
Complete, Integer as MultiPrecisionInteger,
};
Expand Down Expand Up @@ -260,7 +259,9 @@ impl ToFiniteField<u64> for Integer {
}
}
&Integer::Double(n) => field.to_element(n.rem_euclid(field.get_prime() as i128) as u64),
Integer::Large(r) => field.to_element(r.mod_u64(field.get_prime())),
Integer::Large(r) => {
field.to_element(r.rem_euc(field.get_prime()).complete().to_u64().unwrap())
}
}
}
}
Expand Down Expand Up @@ -292,7 +293,7 @@ impl ToFiniteField<Mersenne64> for Integer {
match self {
&Integer::Natural(n) => n.rem_euclid(Mersenne64::PRIME as i64) as u64,
&Integer::Double(n) => n.rem_euclid(Mersenne64::PRIME as i128) as u64,
Integer::Large(r) => r.mod_u64(Mersenne64::PRIME),
Integer::Large(r) => r.rem_euc(Mersenne64::PRIME).complete().to_u64().unwrap(),
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions src/domains/rational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use std::{
ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign},
};

use rug::integer::IntegerExt64;

use crate::{
poly::{gcd::LARGE_U32_PRIMES, polynomial::PolynomialRing, Exponent},
printer::PrintOptions,
Expand Down Expand Up @@ -716,13 +714,18 @@ impl Rational {
Integer::Double(n) => u128::BITS as u64 - (*n as u128).leading_zeros() as u64,
Integer::Large(n) => {
let mut pos = 0;
while let Some(p) = n.find_one_64(pos) {
if p == i64::MAX as u64 {
while let Some(p) = n.find_one(pos) {
if let Some(p2) = pos.checked_add(p) {
if p2 == u32::MAX {
return Err("Could not reconstruct, as the log is too large");
}

pos += 1;
} else {
return Err("Could not reconstruct, as the log is too large");
}
pos = p + 1;
}
pos
pos as u64
}
};

Expand Down

0 comments on commit 4daebee

Please sign in to comment.