Skip to content

Commit 81d885f

Browse files
committed
fix: increase precision of LN_ constants
1 parent 80881ac commit 81d885f

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
name = "bytesize"
33
description = "A utility for human-readable byte count representations"
44
version = "1.3.0"
5-
authors = ["Hyunsik Choi <hyunsik.choi@gmail.com>", "MrCroxx <mrcroxx@outlook.com>"]
5+
authors = [
6+
"Hyunsik Choi <hyunsik.choi@gmail.com>",
7+
"MrCroxx <mrcroxx@outlook.com>",
8+
"Rob Ede <robjtede@icloud.com>",
9+
]
610
keywords = ["byte", "byte-size", "utility", "human-readable", "format"]
711
categories = ["development-tools", "filesystem"]
812
repository = "https://github.com/bytesize-rs/bytesize"

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ const UNITS_IEC: &str = "KMGTPE";
6565

6666
/// SI (decimal) units.
6767
///
68-
///
6968
/// See <https://en.wikipedia.org/wiki/Kilobyte>.
7069
const UNITS_SI: &str = "kMGTPE";
7170

7271
/// `ln(1024) ~= 6.931`
73-
const LN_KIB: f64 = 6.931471806;
72+
const LN_KIB: f64 = 6.931_471_805_599_453;
7473

7574
/// `ln(1000) ~= 6.908`
76-
const LN_KB: f64 = 6.907755279;
75+
const LN_KB: f64 = 6.907_755_278_982_137;
7776

7877
#[derive(Debug, Clone, Default)]
7978
pub enum Format {
@@ -471,7 +470,7 @@ mod tests {
471470
assert_to_string("293.9 KiB", ByteSize::kb(301), Format::IEC);
472471
assert_to_string("301.0 kB", ByteSize::kb(301), Format::SI);
473472

474-
assert_to_string("1024.0 KiB", ByteSize::mib(1), Format::IEC);
473+
assert_to_string("1.0 MiB", ByteSize::mib(1), Format::IEC);
475474
assert_to_string("1.0 MB", ByteSize::mib(1), Format::SI);
476475

477476
assert_to_string("1.9 GiB", ByteSize::mib(1907), Format::IEC);

src/serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ mod tests {
9494
#[test]
9595
fn test_serde_json() {
9696
let json = serde_json::to_string(&ByteSize::mib(1)).unwrap();
97-
assert_eq!(json, "\"1024.0 KiB\"");
97+
assert_eq!(json, "\"1.0 MiB\"");
9898

9999
let deserialized = serde_json::from_str::<ByteSize>(&json).unwrap();
100100
assert_eq!(deserialized.0, 1048576);

0 commit comments

Comments
 (0)