1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-30 12:37:49 +00:00

seq: Move extendedbigdecimal.rs to uucore/features/format

Will make it possible to directly print ExtendedBigDecimal in `seq`,
and gradually get rid of limited f64 precision in other tools
(e.g. `printf`).

Changes are mostly mechanical, we reexport ExtendedBigDecimal directly
in format to keep the imports slightly shorter.
This commit is contained in:
Nicolas Boichat 2025-03-05 10:04:50 +01:00 committed by Sylvestre Ledru
parent b4a9b89f4a
commit 2103646ff7
8 changed files with 15 additions and 12 deletions

2
Cargo.lock generated
View file

@ -3504,6 +3504,7 @@ dependencies = [
name = "uucore" name = "uucore"
version = "0.0.30" version = "0.0.30"
dependencies = [ dependencies = [
"bigdecimal",
"blake2b_simd", "blake2b_simd",
"blake3", "blake3",
"chrono", "chrono",
@ -3523,6 +3524,7 @@ dependencies = [
"md-5", "md-5",
"memchr", "memchr",
"nix", "nix",
"num-traits",
"number_prefix", "number_prefix",
"os_display", "os_display",
"regex", "regex",

View file

@ -3,11 +3,11 @@
// For the full copyright and license information, please view the LICENSE // For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code. // file that was distributed with this source code.
// spell-checker:ignore extendedbigdecimal bigdecimal hexdigit numberparse // spell-checker:ignore extendedbigdecimal bigdecimal hexdigit numberparse
use crate::extendedbigdecimal::ExtendedBigDecimal;
use crate::number::PreciseNumber; use crate::number::PreciseNumber;
use crate::numberparse::ParseNumberError; use crate::numberparse::ParseNumberError;
use bigdecimal::BigDecimal; use bigdecimal::BigDecimal;
use num_traits::FromPrimitive; use num_traits::FromPrimitive;
use uucore::format::ExtendedBigDecimal;
/// The base of the hex number system /// The base of the hex number system
const HEX_RADIX: u32 = 16; const HEX_RADIX: u32 = 16;

View file

@ -5,7 +5,7 @@
// spell-checker:ignore extendedbigdecimal // spell-checker:ignore extendedbigdecimal
use num_traits::Zero; use num_traits::Zero;
use crate::extendedbigdecimal::ExtendedBigDecimal; use uucore::format::ExtendedBigDecimal;
/// A number with a specified number of integer and fractional digits. /// A number with a specified number of integer and fractional digits.
/// ///

View file

@ -15,9 +15,9 @@ use num_bigint::Sign;
use num_traits::Num; use num_traits::Num;
use num_traits::Zero; use num_traits::Zero;
use crate::extendedbigdecimal::ExtendedBigDecimal;
use crate::hexadecimalfloat; use crate::hexadecimalfloat;
use crate::number::PreciseNumber; use crate::number::PreciseNumber;
use uucore::format::ExtendedBigDecimal;
/// An error returned when parsing a number fails. /// An error returned when parsing a number fails.
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
@ -381,8 +381,8 @@ impl FromStr for PreciseNumber {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use bigdecimal::BigDecimal; use bigdecimal::BigDecimal;
use uucore::format::ExtendedBigDecimal;
use crate::extendedbigdecimal::ExtendedBigDecimal;
use crate::number::PreciseNumber; use crate::number::PreciseNumber;
use crate::numberparse::ParseNumberError; use crate::numberparse::ParseNumberError;

View file

@ -10,11 +10,10 @@ use clap::{Arg, ArgAction, Command};
use num_traits::{ToPrimitive, Zero}; use num_traits::{ToPrimitive, Zero};
use uucore::error::{FromIo, UResult}; use uucore::error::{FromIo, UResult};
use uucore::format::{num_format, sprintf, Format, FormatArgument}; use uucore::format::{num_format, sprintf, ExtendedBigDecimal, Format, FormatArgument};
use uucore::{format_usage, help_about, help_usage}; use uucore::{format_usage, help_about, help_usage};
mod error; mod error;
mod extendedbigdecimal;
mod hexadecimalfloat; mod hexadecimalfloat;
// public to allow fuzzing // public to allow fuzzing
@ -24,7 +23,6 @@ pub mod number;
mod number; mod number;
mod numberparse; mod numberparse;
use crate::error::SeqError; use crate::error::SeqError;
use crate::extendedbigdecimal::ExtendedBigDecimal;
use crate::number::PreciseNumber; use crate::number::PreciseNumber;
const ABOUT: &str = help_about!("seq.md"); const ABOUT: &str = help_about!("seq.md");

View file

@ -1,4 +1,4 @@
# spell-checker:ignore (features) zerocopy # spell-checker:ignore (features) bigdecimal zerocopy
[package] [package]
name = "uucore" name = "uucore"
@ -58,6 +58,8 @@ blake3 = { workspace = true, optional = true }
sm3 = { workspace = true, optional = true } sm3 = { workspace = true, optional = true }
crc32fast = { workspace = true, optional = true } crc32fast = { workspace = true, optional = true }
regex = { workspace = true, optional = true } regex = { workspace = true, optional = true }
bigdecimal = { workspace = true, optional = true }
num-traits = { workspace = true, optional = true }
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
walkdir = { workspace = true, optional = true } walkdir = { workspace = true, optional = true }
@ -94,7 +96,7 @@ fs = ["dunce", "libc", "winapi-util", "windows-sys"]
fsext = ["libc", "windows-sys"] fsext = ["libc", "windows-sys"]
fsxattr = ["xattr"] fsxattr = ["xattr"]
lines = [] lines = []
format = ["itertools", "quoting-style"] format = ["bigdecimal", "itertools", "num-traits", "quoting-style"]
mode = ["libc"] mode = ["libc"]
perms = ["entries", "libc", "walkdir"] perms = ["entries", "libc", "walkdir"]
buf-copy = [] buf-copy = []

View file

@ -2,7 +2,7 @@
// //
// For the full copyright and license information, please view the LICENSE // For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code. // file that was distributed with this source code.
// spell-checker:ignore bigdecimal extendedbigdecimal extendedbigint // spell-checker:ignore bigdecimal extendedbigdecimal
//! An arbitrary precision float that can also represent infinity, NaN, etc. //! An arbitrary precision float that can also represent infinity, NaN, etc.
//! //!
//! The finite values are stored as [`BigDecimal`] instances. Because //! The finite values are stored as [`BigDecimal`] instances. Because
@ -68,7 +68,6 @@ pub enum ExtendedBigDecimal {
} }
impl ExtendedBigDecimal { impl ExtendedBigDecimal {
#[cfg(test)]
pub fn zero() -> Self { pub fn zero() -> Self {
Self::BigDecimal(0.into()) Self::BigDecimal(0.into())
} }
@ -197,7 +196,7 @@ mod tests {
use bigdecimal::BigDecimal; use bigdecimal::BigDecimal;
use num_traits::Zero; use num_traits::Zero;
use crate::extendedbigdecimal::ExtendedBigDecimal; use crate::format::extendedbigdecimal::ExtendedBigDecimal;
#[test] #[test]
fn test_addition_infinity() { fn test_addition_infinity() {

View file

@ -32,12 +32,14 @@
mod argument; mod argument;
mod escape; mod escape;
pub mod extendedbigdecimal;
pub mod human; pub mod human;
pub mod num_format; pub mod num_format;
pub mod num_parser; pub mod num_parser;
mod spec; mod spec;
pub use argument::*; pub use argument::*;
pub use extendedbigdecimal::ExtendedBigDecimal;
pub use spec::Spec; pub use spec::Spec;
use std::{ use std::{
error::Error, error::Error,