Skip to content

Commit 7cfea4f

Browse files
authored
Merge pull request #19 from jlapeyre/reset-precision-in-config
Reset the fp precision before synthesis The precision is stored statically. Before this PR, the precision of theta is 1000 on the first synthesis and something else on subsequent runs. This PR resets it to its initial value before starting synthesis.
2 parents 07630ee + a0e9485 commit 7cfea4f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/common.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ use dashu_int::IBig;
77
use once_cell::sync::Lazy;
88
use std::sync::atomic::{AtomicUsize, Ordering};
99

10-
pub static PREC_BITS: AtomicUsize = AtomicUsize::new(1000);
10+
const PREC_BITS_INITIAL: usize = 1000;
11+
pub static PREC_BITS: AtomicUsize = AtomicUsize::new(PREC_BITS_INITIAL);
12+
13+
// Reset precision to the initial value
14+
pub fn reset_prec_bits() {
15+
PREC_BITS.store(PREC_BITS_INITIAL, Ordering::Relaxed);
16+
}
1117

1218
pub fn set_prec_bits(bits: usize) {
1319
PREC_BITS.store(bits, Ordering::Relaxed);

src/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::common::ib_to_bf_prec;
2-
use crate::common::set_prec_bits;
2+
use crate::common::{reset_prec_bits, set_prec_bits};
33
use dashu_float::round::mode::HalfEven;
44
use dashu_float::FBig;
55
use dashu_int::{IBig, UBig};
@@ -77,6 +77,12 @@ pub fn config_from_theta_epsilon(
7777
verbose: bool,
7878
) -> GridSynthConfig {
7979
let (theta_num, theta_den) = parse_decimal_with_exponent(&theta.to_string()).unwrap();
80+
81+
// The desired floating precision is initialized in module common.
82+
// It has the initial value the first time this function is called.
83+
// But, on subsequent calls, the precision has changed.
84+
// We reset it so that the precison is the same at the beginning of every synthesis.
85+
reset_prec_bits();
8086
let theta = ib_to_bf_prec(theta_num) / ib_to_bf_prec(theta_den);
8187
let (epsilon_num, epsilon_den) = parse_decimal_with_exponent(&epsilon.to_string()).unwrap();
8288
// The magic number 12 safely overapproximates the bits of precision.

0 commit comments

Comments
 (0)