Skip to content

Commit 2509946

Browse files
committed
num: Separate public API from internal implementations
Currently we have a single `core::num` module that contains both thin wrapper API and higher-complexity numeric routines. Restructure this by moving implementation details to a new `imp` module. This results in a more clean separation of what is actually user-facing compared to items that have a stability attribute because they are public for testing.
1 parent 310ae8c commit 2509946

51 files changed

Lines changed: 172 additions & 148 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

library/core/src/fmt/float.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::fmt::{Debug, Display, Formatter, LowerExp, Result, UpperExp};
22
use crate::mem::MaybeUninit;
3-
use crate::num::{flt2dec, fmt as numfmt};
3+
use crate::num::imp::{flt2dec, fmt as numfmt};
44

55
#[doc(hidden)]
66
trait GeneralFormat: PartialOrd {

library/core/src/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::cell::{Cell, Ref, RefCell, RefMut, SyncUnsafeCell, UnsafeCell};
66
use crate::char::EscapeDebugExtArgs;
77
use crate::hint::assert_unchecked;
88
use crate::marker::{PhantomData, PointeeSized};
9-
use crate::num::fmt as numfmt;
9+
use crate::num::imp::fmt as numfmt;
1010
use crate::ops::Deref;
1111
use crate::ptr::NonNull;
1212
use crate::{iter, mem, result, str};

library/core/src/fmt/num.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::fmt::NumBuffer;
44
use crate::mem::MaybeUninit;
5-
use crate::num::fmt as numfmt;
5+
use crate::num::imp::fmt as numfmt;
66
use crate::{fmt, str};
77

88
/// Formatting of integers with a non-decimal radix.

library/core/src/num/f16.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use crate::convert::FloatToInt;
1515
use crate::num::FpCategory;
1616
#[cfg(not(test))]
17-
use crate::num::libm;
17+
use crate::num::imp::libm;
1818
use crate::panic::const_assert;
1919
use crate::{intrinsics, mem};
2020

library/core/src/num/f32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ impl f32 {
16211621
#[unstable(feature = "core_float_math", issue = "137578")]
16221622
pub mod math {
16231623
use crate::intrinsics;
1624-
use crate::num::libm;
1624+
use crate::num::imp::libm;
16251625

16261626
/// Experimental version of `floor` in `core`. See [`f32::floor`] for details.
16271627
///

library/core/src/num/f64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ impl f64 {
16191619
/// They will be stabilized as inherent methods._
16201620
pub mod math {
16211621
use crate::intrinsics;
1622-
use crate::num::libm;
1622+
use crate::num::imp::libm;
16231623

16241624
/// Experimental version of `floor` in `core`. See [`f64::floor`] for details.
16251625
///
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ macro_rules! define_bignum {
251251

252252
/// Multiplies itself by `5^e` and returns its own mutable reference.
253253
pub fn mul_pow5(&mut self, mut e: usize) -> &mut $name {
254-
use crate::num::bignum::SMALL_POW5;
254+
use crate::num::imp::bignum::SMALL_POW5;
255255

256256
// There are exactly n trailing zeros on 2^n, and the only relevant digit sizes
257257
// are consecutive powers of two, so this is well suited index for the table.
@@ -281,7 +281,7 @@ macro_rules! define_bignum {
281281
pub fn mul_digits<'a>(&'a mut self, other: &[$ty]) -> &'a mut $name {
282282
// the internal routine. works best when aa.len() <= bb.len().
283283
fn mul_inner(ret: &mut [$ty; $n], aa: &[$ty], bb: &[$ty]) -> usize {
284-
use crate::num::bignum::FullOps;
284+
use crate::num::imp::bignum::FullOps;
285285

286286
let mut retsz = 0;
287287
for (i, &a) in aa.iter().enumerate() {
@@ -320,7 +320,7 @@ macro_rules! define_bignum {
320320
/// Divides itself by a digit-sized `other` and returns its own
321321
/// mutable reference *and* the remainder.
322322
pub fn div_rem_small(&mut self, other: $ty) -> (&mut $name, $ty) {
323-
use crate::num::bignum::FullOps;
323+
use crate::num::imp::bignum::FullOps;
324324

325325
assert!(other > 0);
326326

File renamed without changes.

library/core/src/num/dec2flt/decimal.rs renamed to library/core/src/num/imp/dec2flt/decimal.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Representation of a float as the significant digits and exponent.
22
3-
use crate::num::dec2flt::float::RawFloat;
4-
use crate::num::dec2flt::fpu::set_precision;
3+
use dec2flt::float::RawFloat;
4+
use dec2flt::fpu::set_precision;
5+
6+
use crate::num::imp::dec2flt;
57

68
const INT_POW10: [u64; 16] = [
79
1,

library/core/src/num/dec2flt/decimal_seq.rs renamed to library/core/src/num/imp/dec2flt/decimal_seq.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
//! algorithm can be found in "ParseNumberF64 by Simple Decimal Conversion",
1010
//! available online: <https://nigeltao.github.io/blog/2020/parse-number-f64-simple.html>.
1111
12-
use crate::num::dec2flt::common::{ByteSlice, is_8digits};
12+
use dec2flt::common::{ByteSlice, is_8digits};
13+
14+
use crate::num::imp::dec2flt;
1315

1416
/// A decimal floating-point number, represented as a sequence of decimal digits.
1517
#[derive(Clone, Debug, PartialEq)]

0 commit comments

Comments
 (0)