Skip to content

Commit 623dd94

Browse files
authored
Merge pull request #1 from boa-dev/fix/buffer-overflow
2 parents fe366fa + c42808d commit 623dd94

File tree

14 files changed

+79
-115
lines changed

14 files changed

+79
-115
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "ryu-js"
3-
version = "1.0.5" # don't forget to update html_root_url
3+
version = "0.1.0" # don't forget to update html_root_url
44
authors = ["David Tolnay <dtolnay@gmail.com>"]
55
license = "Apache-2.0 OR BSL-1.0"
6-
description = "Fast floating point to string conversion"
7-
repository = "https://github.com/dtolnay/ryu"
8-
documentation = "https://docs.rs/ryu"
6+
description = "Fast floating point to string conversion, ECMAScript compliant."
7+
repository = "https://github.com/boa-dev/ryu-js"
8+
documentation = "https://docs.rs/ryu-js"
99
readme = "README.md"
1010
edition = "2018"
1111

README.md

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Ryū
1+
# Ryū-js
22

3-
[<img alt="github" src="https://img.shields.io/badge/github-dtolnay/ryu-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/ryu)
4-
[<img alt="crates.io" src="https://img.shields.io/crates/v/ryu.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/ryu)
5-
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-ryu-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/ryu)
6-
[<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/ryu/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/ryu/actions?query=branch%3Amaster)
3+
Ryū-js is a fork of the [ryu][ryu-crate] crate adjusted to comply to the ECMAScript [number-to-string][number-to-string] algorithm.
4+
This crate is used in the `Boa` crate for number to string conversions
5+
6+
[ryu-crate]: https://crates.io/crates/ryu
7+
[number-to-string]: https://tc39.es/ecma262/#sec-numeric-types-number-tostring
78

89
Pure Rust implementation of Ryū, an algorithm to quickly convert floating point
910
numbers to decimal strings.
@@ -15,46 +16,27 @@ under the creative commons CC-BY-SA license.
1516
This Rust implementation is a line-by-line port of Ulf Adams' implementation in
1617
C, [https://github.com/ulfjack/ryu][upstream].
1718

18-
*Requirements: this crate supports any compiler version back to rustc 1.31; it
19-
uses nothing from the Rust standard library so is usable from no_std crates.*
20-
2119
[paper]: https://dl.acm.org/citation.cfm?id=3192369
2220
[upstream]: https://github.com/ulfjack/ryu/tree/1c413e127f8d02afd12eb6259bc80163722f1385
2321

2422
```toml
2523
[dependencies]
26-
ryu = "1.0"
24+
ryu-js = "0.1"
2725
```
2826

2927
## Example
3028

3129
```rust
3230
fn main() {
33-
let mut buffer = ryu::Buffer::new();
31+
let mut buffer = ryu_js::Buffer::new();
3432
let printed = buffer.format(1.234);
3533
assert_eq!(printed, "1.234");
3634
}
3735
```
3836

3937
## Performance
4038

41-
You can run upstream's benchmarks with:
42-
43-
```console
44-
$ git clone https://github.com/ulfjack/ryu c-ryu
45-
$ cd c-ryu
46-
$ bazel run -c opt //ryu/benchmark
47-
```
48-
49-
And the same benchmark against our implementation with:
50-
51-
```console
52-
$ git clone https://github.com/dtolnay/ryu rust-ryu
53-
$ cd rust-ryu
54-
$ cargo run --example upstream_benchmark --release
55-
```
56-
57-
These benchmarks measure the average time to print a 32-bit float and average
39+
The benchmarks measure the average time to print a 32-bit float and average
5840
time to print a 64-bit float, where the inputs are distributed as uniform random
5941
bit patterns 32 and 64 bits wide.
6042

benches/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ macro_rules! benches {
1515
$(
1616
#[bench]
1717
fn $name(b: &mut Bencher) {
18-
let mut buf = ryu::Buffer::new();
18+
let mut buf = ryu_js::Buffer::new();
1919

2020
b.iter(move || {
2121
let value = black_box($value);

examples/upstream_benchmark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ macro_rules! benchmark {
5353

5454
let t1 = std::time::SystemTime::now();
5555
for _ in 0..ITERATIONS {
56-
throwaway += ryu::Buffer::new().format_finite(f).len();
56+
throwaway += ryu_js::Buffer::new().format_finite(f).len();
5757
}
5858
let duration = t1.elapsed().unwrap();
5959
let nanos = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;

src/buffer/mod.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
use crate::raw;
22
#[cfg(maybe_uninit)]
33
use core::mem::MaybeUninit;
4-
use core::{mem, slice, str};
4+
use core::{slice, str};
55
#[cfg(feature = "no-panic")]
66
use no_panic::no_panic;
77

8-
const NAN: &'static str = "NaN";
9-
const INFINITY: &'static str = "Infinity";
10-
const NEG_INFINITY: &'static str = "-Infinity";
8+
const NAN: &str = "NaN";
9+
const INFINITY: &str = "Infinity";
10+
const NEG_INFINITY: &str = "-Infinity";
1111

1212
/// Safe API for formatting floating point numbers to text.
1313
///
1414
/// ## Example
1515
///
1616
/// ```
17-
/// let mut buffer = ryu::Buffer::new();
17+
/// let mut buffer = ryu_js::Buffer::new();
1818
/// let printed = buffer.format_finite(1.234);
1919
/// assert_eq!(printed, "1.234");
2020
/// ```
2121
pub struct Buffer {
2222
#[cfg(maybe_uninit)]
23-
bytes: [MaybeUninit<u8>; 24],
23+
bytes: [MaybeUninit<u8>; 25],
2424
#[cfg(not(maybe_uninit))]
25-
bytes: [u8; 24],
25+
bytes: [u8; 25],
2626
}
2727

2828
impl Buffer {
@@ -34,11 +34,11 @@ impl Buffer {
3434
// assume_init is safe here, since this is an array of MaybeUninit, which does not need
3535
// to be initialized.
3636
#[cfg(maybe_uninit)]
37-
let bytes = [MaybeUninit::<u8>::uninit(); 24];
37+
let bytes = [MaybeUninit::<u8>::uninit(); 25];
3838
#[cfg(not(maybe_uninit))]
3939
let bytes = unsafe { mem::uninitialized() };
4040

41-
Buffer { bytes: bytes }
41+
Buffer { bytes }
4242
}
4343

4444
/// Print a floating point number into this buffer and return a reference to
@@ -47,11 +47,13 @@ impl Buffer {
4747
/// # Special cases
4848
///
4949
/// This function formats NaN as the string "NaN", positive infinity as
50-
/// "inf", and negative infinity as "-inf" to match std::fmt.
50+
/// "Infinity", and negative infinity as "-Infinity" to match the [ECMAScript specification][spec].
5151
///
5252
/// If your input is known to be finite, you may get better performance by
5353
/// calling the `format_finite` method instead of `format` to avoid the
5454
/// checks for special cases.
55+
///
56+
/// [spec]: https://tc39.es/ecma262/#sec-numeric-types-number-tostring
5557
#[cfg_attr(feature = "no-panic", inline)]
5658
#[cfg_attr(feature = "no-panic", no_panic)]
5759
pub fn format<F: Float>(&mut self, f: F) -> &str {
@@ -125,7 +127,7 @@ impl Sealed for f32 {
125127
#[inline]
126128
fn is_nonfinite(self) -> bool {
127129
const EXP_MASK: u32 = 0x7f800000;
128-
let bits = unsafe { mem::transmute::<f32, u32>(self) };
130+
let bits = self.to_bits();
129131
bits & EXP_MASK == EXP_MASK
130132
}
131133

@@ -134,7 +136,7 @@ impl Sealed for f32 {
134136
fn format_nonfinite(self) -> &'static str {
135137
const MANTISSA_MASK: u32 = 0x007fffff;
136138
const SIGN_MASK: u32 = 0x80000000;
137-
let bits = unsafe { mem::transmute::<f32, u32>(self) };
139+
let bits = self.to_bits();
138140
if bits & MANTISSA_MASK != 0 {
139141
NAN
140142
} else if bits & SIGN_MASK != 0 {
@@ -154,7 +156,7 @@ impl Sealed for f64 {
154156
#[inline]
155157
fn is_nonfinite(self) -> bool {
156158
const EXP_MASK: u64 = 0x7ff0000000000000;
157-
let bits = unsafe { mem::transmute::<f64, u64>(self) };
159+
let bits = self.to_bits();
158160
bits & EXP_MASK == EXP_MASK
159161
}
160162

@@ -163,7 +165,7 @@ impl Sealed for f64 {
163165
fn format_nonfinite(self) -> &'static str {
164166
const MANTISSA_MASK: u64 = 0x000fffffffffffff;
165167
const SIGN_MASK: u64 = 0x8000000000000000;
166-
let bits = unsafe { mem::transmute::<f64, u64>(self) };
168+
let bits = self.to_bits();
167169
if bits & MANTISSA_MASK != 0 {
168170
NAN
169171
} else if bits & SIGN_MASK != 0 {

src/lib.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
//! [![github]](https://github.com/dtolnay/ryu)&ensp;[![crates-io]](https://crates.io/crates/ryu)&ensp;[![docs-rs]](https://docs.rs/ryu)
2-
//!
3-
//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
4-
//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
5-
//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K
6-
//!
7-
//! <br>
8-
//!
9-
//! Pure Rust implementation of Ryū, an algorithm to quickly convert floating
10-
//! point numbers to decimal strings.
1+
//! ECMAScript compliant pure Rust implementation of Ryū, an algorithm to quickly
2+
//! convert floating point numbers to decimal strings.
113
//!
124
//! The PLDI'18 paper [*Ryū: fast float-to-string conversion*][paper] by Ulf
135
//! Adams includes a complete correctness proof of the algorithm. The paper is
@@ -23,31 +15,15 @@
2315
//!
2416
//! ```
2517
//! fn main() {
26-
//! let mut buffer = ryu::Buffer::new();
18+
//! let mut buffer = ryu_js::Buffer::new();
2719
//! let printed = buffer.format(1.234);
2820
//! assert_eq!(printed, "1.234");
2921
//! }
3022
//! ```
3123
//!
3224
//! ## Performance
3325
//!
34-
//! You can run upstream's benchmarks with:
35-
//!
36-
//! ```console
37-
//! $ git clone https://github.com/ulfjack/ryu c-ryu
38-
//! $ cd c-ryu
39-
//! $ bazel run -c opt //ryu/benchmark
40-
//! ```
41-
//!
42-
//! And the same benchmark against our implementation with:
43-
//!
44-
//! ```console
45-
//! $ git clone https://github.com/dtolnay/ryu rust-ryu
46-
//! $ cd rust-ryu
47-
//! $ cargo run --example upstream_benchmark --release
48-
//! ```
49-
//!
50-
//! These benchmarks measure the average time to print a 32-bit float and average
26+
//! The benchmarks measure the average time to print a 32-bit float and average
5127
//! time to print a 64-bit float, where the inputs are distributed as uniform random
5228
//! bit patterns 32 and 64 bits wide.
5329
//!
@@ -89,7 +65,7 @@
8965
//! notation.
9066
9167
#![no_std]
92-
#![doc(html_root_url = "https://docs.rs/ryu/1.0.5")]
68+
#![doc(html_root_url = "https://docs.rs/ryu-js/0.1.0")]
9369
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
9470
#![cfg_attr(
9571
feature = "cargo-clippy",

src/pretty/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use self::mantissa::*;
66
use crate::common;
77
use crate::d2s::{self, *};
88
use crate::f2s::*;
9-
use core::{mem, ptr};
9+
use core::ptr;
1010
#[cfg(feature = "no-panic")]
1111
use no_panic::no_panic;
1212

1313
/// Print f64 to the given buffer and return number of bytes written.
1414
///
15-
/// At most 24 bytes will be written.
15+
/// At most 25 bytes will be written.
1616
///
1717
/// ## Special cases
1818
///
@@ -41,7 +41,7 @@ use no_panic::no_panic;
4141
///
4242
/// unsafe {
4343
/// let mut buffer = [MaybeUninit::<u8>::uninit(); 24];
44-
/// let len = ryu::raw::format64(f, buffer.as_mut_ptr() as *mut u8);
44+
/// let len = ryu_js::raw::format64(f, buffer.as_mut_ptr() as *mut u8);
4545
/// let slice = slice::from_raw_parts(buffer.as_ptr() as *const u8, len);
4646
/// let print = str::from_utf8_unchecked(slice);
4747
/// assert_eq!(print, "1.234");
@@ -50,7 +50,7 @@ use no_panic::no_panic;
5050
#[must_use]
5151
#[cfg_attr(feature = "no-panic", no_panic)]
5252
pub unsafe fn format64(f: f64, result: *mut u8) -> usize {
53-
let bits = mem::transmute::<f64, u64>(f);
53+
let bits = f.to_bits();
5454
let sign = ((bits >> (DOUBLE_MANTISSA_BITS + DOUBLE_EXPONENT_BITS)) & 1) != 0;
5555
let ieee_mantissa = bits & ((1u64 << DOUBLE_MANTISSA_BITS) - 1);
5656
let ieee_exponent =
@@ -146,7 +146,7 @@ pub unsafe fn format64(f: f64, result: *mut u8) -> usize {
146146
///
147147
/// unsafe {
148148
/// let mut buffer = [MaybeUninit::<u8>::uninit(); 16];
149-
/// let len = ryu::raw::format32(f, buffer.as_mut_ptr() as *mut u8);
149+
/// let len = ryu_js::raw::format32(f, buffer.as_mut_ptr() as *mut u8);
150150
/// let slice = slice::from_raw_parts(buffer.as_ptr() as *const u8, len);
151151
/// let print = str::from_utf8_unchecked(slice);
152152
/// assert_eq!(print, "1.234");
@@ -155,7 +155,7 @@ pub unsafe fn format64(f: f64, result: *mut u8) -> usize {
155155
#[must_use]
156156
#[cfg_attr(feature = "no-panic", no_panic)]
157157
pub unsafe fn format32(f: f32, result: *mut u8) -> usize {
158-
let bits = mem::transmute::<f32, u32>(f);
158+
let bits = f.to_bits();
159159
let sign = ((bits >> (FLOAT_MANTISSA_BITS + FLOAT_EXPONENT_BITS)) & 1) != 0;
160160
let ieee_mantissa = bits & ((1u32 << FLOAT_MANTISSA_BITS) - 1);
161161
let ieee_exponent =

src/s2d.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ pub fn s2d(buffer: &[u8]) -> Result<f64, Error> {
114114
// whether the conversion was exact (trailing_zeros).
115115
let e2: i32;
116116
let m2: u64;
117-
let mut trailing_zeros: bool;
118-
if e10 >= 0 {
117+
let mut trailing_zeros = if e10 >= 0 {
119118
// The length of m * 10^e in bits is:
120119
// log2(m10 * 10^e10) = log2(m10) + e10 log2(10) = log2(m10) + e10 + e10 * log2(5)
121120
//
@@ -151,8 +150,7 @@ pub fn s2d(buffer: &[u8]) -> Result<f64, Error> {
151150
// requires that the largest power of 2 that divides m10 + e10 is
152151
// greater than e2. If e2 is less than e10, then the result must be
153152
// exact. Otherwise we use the existing multiple_of_power_of_2 function.
154-
trailing_zeros =
155-
e2 < e10 || e2 - e10 < 64 && multiple_of_power_of_2(m10, (e2 - e10) as u32);
153+
e2 < e10 || e2 - e10 < 64 && multiple_of_power_of_2(m10, (e2 - e10) as u32)
156154
} else {
157155
e2 = floor_log2(m10)
158156
.wrapping_add(e10 as u32)
@@ -169,8 +167,9 @@ pub fn s2d(buffer: &[u8]) -> Result<f64, Error> {
169167
unsafe { d2s::DOUBLE_POW5_INV_SPLIT.get_unchecked(-e10 as usize) },
170168
j as u32,
171169
);
172-
trailing_zeros = multiple_of_power_of_5(m10, -e10 as u32);
173-
}
170+
171+
multiple_of_power_of_5(m10, -e10 as u32)
172+
};
174173

175174
// Compute the final IEEE exponent.
176175
let mut ieee_e2 = i32::max(0, e2 + DOUBLE_EXPONENT_BIAS as i32 + floor_log2(m2) as i32) as u32;

src/s2f.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ pub fn s2f(buffer: &[u8]) -> Result<f32, Error> {
114114
// whether the conversion was exact (trailing_zeros).
115115
let e2: i32;
116116
let m2: u32;
117-
let mut trailing_zeros: bool;
118-
if e10 >= 0 {
117+
let mut trailing_zeros = if e10 >= 0 {
119118
// The length of m * 10^e in bits is:
120119
// log2(m10 * 10^e10) = log2(m10) + e10 log2(10) = log2(m10) + e10 + e10 * log2(5)
121120
//
@@ -146,8 +145,7 @@ pub fn s2f(buffer: &[u8]) -> Result<f32, Error> {
146145
// requires that the largest power of 2 that divides m10 + e10 is
147146
// greater than e2. If e2 is less than e10, then the result must be
148147
// exact. Otherwise we use the existing multiple_of_power_of_2 function.
149-
trailing_zeros =
150-
e2 < e10 || e2 - e10 < 32 && multiple_of_power_of_2_32(m10, (e2 - e10) as u32);
148+
e2 < e10 || e2 - e10 < 32 && multiple_of_power_of_2_32(m10, (e2 - e10) as u32)
151149
} else {
152150
e2 = floor_log2(m10)
153151
.wrapping_add(e10 as u32)
@@ -159,8 +157,9 @@ pub fn s2f(buffer: &[u8]) -> Result<f32, Error> {
159157
.wrapping_sub(1)
160158
.wrapping_add(f2s::FLOAT_POW5_INV_BITCOUNT);
161159
m2 = mul_pow5_inv_div_pow2(m10, -e10 as u32, j);
162-
trailing_zeros = multiple_of_power_of_5_32(m10, -e10 as u32);
163-
}
160+
161+
multiple_of_power_of_5_32(m10, -e10 as u32)
162+
};
164163

165164
// Compute the final IEEE exponent.
166165
let mut ieee_e2 = i32::max(0, e2 + FLOAT_EXPONENT_BIAS as i32 + floor_log2(m2) as i32) as u32;

tests/common_test.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,3 @@ fn test_log10_pow5() {
6666
assert_eq!(2, log10_pow5(4));
6767
assert_eq!(1831, log10_pow5(2620));
6868
}
69-
70-
#[test]
71-
fn test_float_to_bits() {
72-
assert_eq!(0, 0.0_f32.to_bits());
73-
assert_eq!(0x40490fda, 3.1415926_f32.to_bits());
74-
}
75-
76-
#[test]
77-
fn test_double_to_bits() {
78-
assert_eq!(0, 0.0_f64.to_bits());
79-
assert_eq!(
80-
0x400921FB54442D18,
81-
3.1415926535897932384626433_f64.to_bits(),
82-
);
83-
}

0 commit comments

Comments
 (0)