mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1716518 - Upgrade dtoa to v0.4.8. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D117783
This commit is contained in:
parent
54ab66d8a0
commit
310a80f22e
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1207,9 +1207,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dtoa"
|
||||
version = "0.4.2"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
|
||||
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
|
||||
|
||||
[[package]]
|
||||
name = "dtoa-short"
|
||||
|
2
third_party/rust/dtoa/.cargo-checksum.json
vendored
2
third_party/rust/dtoa/.cargo-checksum.json
vendored
@ -1 +1 @@
|
||||
{"files":{"Cargo.toml":"f7341a8bad6e4c144f5d39e3a2254443738555214c26e1e92de45bbab02bb424","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"e18259ab3aa7f39a194795bdad8039b3c5fd544f6dd922526c9326c44842b76d","README.md":"2a26b3c04192f933e2a28f1f7069e0df4b0b24fbd3cef53ab9a2318a53a65553","benches/bench.rs":"ac713ab4e1c668dea70416504955563fcd6bd2982ae1cfa3a1c0043e09dd893f","src/diyfp.rs":"81754c3d1b8ff2347a506187ef43a666f09e20ae0e53436226c969d7e3f737dc","src/dtoa.rs":"f5cdd96d6ac9d3c50289a090a6d6801d36cb121c2a5e6d8acd1aa41013fded76","src/lib.rs":"141f175d15e6c5d0f0833f6c758305aa2b101bacfa9100f5d4cd98601df00e11","tests/test.rs":"296f3c322e08508fd372e436434fdd209bb911cab2124ea654d5f78d90f3eeea"},"package":"09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"}
|
||||
{"files":{"Cargo.toml":"657b9f00844e4f422237ebd26991476b160da598894d98d1d0be57e4e553c986","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"3416361ff0af6647a1616cc020766df798d683b8645f0d9270512277ee6cb47e","benches/bench.rs":"ac713ab4e1c668dea70416504955563fcd6bd2982ae1cfa3a1c0043e09dd893f","src/diyfp.rs":"89f685b3beb13dff8d4c2e28e16c4891013f7b387e625c5151267b2cd077df1d","src/dtoa.rs":"c70bb76acde7b749dfc9273fd556c73960027b3534c1f56a32768bf8f25985ff","src/lib.rs":"43eb71b7e5d5f802ad3c49148db4e27f9d911aa69ea77777f95feefc2e1f1e93","tests/test.rs":"296f3c322e08508fd372e436434fdd209bb911cab2124ea654d5f78d90f3eeea"},"package":"56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"}
|
10
third_party/rust/dtoa/Cargo.toml
vendored
10
third_party/rust/dtoa/Cargo.toml
vendored
@ -3,7 +3,7 @@
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g. crates.io) dependencies
|
||||
# to registry (e.g., crates.io) dependencies
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
@ -12,12 +12,14 @@
|
||||
|
||||
[package]
|
||||
name = "dtoa"
|
||||
version = "0.4.2"
|
||||
version = "0.4.8"
|
||||
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||
exclude = ["performance.png"]
|
||||
description = "Fast functions for printing floating-point primitives to an io::Write"
|
||||
documentation = "https://github.com/dtolnay/dtoa"
|
||||
documentation = "https://docs.rs/dtoa"
|
||||
readme = "README.md"
|
||||
categories = ["value-formatting"]
|
||||
license = "MIT/Apache-2.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/dtolnay/dtoa"
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
2
third_party/rust/dtoa/LICENSE-MIT
vendored
2
third_party/rust/dtoa/LICENSE-MIT
vendored
@ -1,5 +1,3 @@
|
||||
Copyright (c) 2016 Itoa Developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
|
109
third_party/rust/dtoa/README.md
vendored
109
third_party/rust/dtoa/README.md
vendored
@ -1,69 +1,80 @@
|
||||
dtoa
|
||||
====
|
||||
|
||||
[![Build Status](https://api.travis-ci.org/dtolnay/dtoa.svg?branch=master)](https://travis-ci.org/dtolnay/dtoa)
|
||||
[![Latest Version](https://img.shields.io/crates/v/dtoa.svg)](https://crates.io/crates/dtoa)
|
||||
[<img alt="github" src="https://img.shields.io/badge/github-dtolnay/dtoa-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/dtoa)
|
||||
[<img alt="crates.io" src="https://img.shields.io/crates/v/dtoa.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/dtoa)
|
||||
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-dtoa-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/dtoa)
|
||||
[<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/dtoa/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/dtoa/actions?query=branch%3Amaster)
|
||||
|
||||
This crate provides fast functions for printing floating-point primitives to an
|
||||
[`io::Write`](https://doc.rust-lang.org/std/io/trait.Write.html). The
|
||||
implementation is a straightforward Rust port of [Milo
|
||||
Yip](https://github.com/miloyip)'s C++ implementation
|
||||
[dtoa.h](https://github.com/miloyip/rapidjson/blob/master/include/rapidjson/internal/dtoa.h).
|
||||
The original C++ code of each function is included in comments.
|
||||
[`io::Write`]. The implementation is a straightforward Rust port of [Milo Yip]'s
|
||||
C++ implementation [dtoa.h]. The original C++ code of each function is included
|
||||
in comments.
|
||||
|
||||
See also [`itoa`](https://github.com/dtolnay/itoa) for printing integer
|
||||
primitives.
|
||||
See also [`itoa`] for printing integer primitives.
|
||||
|
||||
## Performance (lower is better)
|
||||
*Version requirement: rustc 1.0+*
|
||||
|
||||
![performance](https://raw.githubusercontent.com/dtolnay/dtoa/master/performance.png)
|
||||
|
||||
## Functions
|
||||
|
||||
```rust
|
||||
extern crate dtoa;
|
||||
|
||||
// write to a vector or other io::Write
|
||||
let mut buf = Vec::new();
|
||||
dtoa::write(&mut buf, 2.71828f64)?;
|
||||
println!("{:?}", buf);
|
||||
|
||||
// write to a stack buffer
|
||||
let mut bytes = [b'\0'; 20];
|
||||
let n = dtoa::write(&mut bytes[..], 2.71828f64)?;
|
||||
println!("{:?}", &bytes[..n]);
|
||||
```
|
||||
|
||||
The function signature is:
|
||||
|
||||
```rust
|
||||
fn write<W: io::Write, V: dtoa::Floating>(writer: W, value: V) -> io::Result<()>
|
||||
```
|
||||
|
||||
where `dtoa::Floating` is implemented for `f32` and `f64`. The return value
|
||||
gives the number of bytes written.
|
||||
|
||||
## Dependency
|
||||
|
||||
Dtoa is available on [crates.io](https://crates.io/crates/dtoa). Use the
|
||||
following in `Cargo.toml`:
|
||||
[`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
|
||||
[Milo Yip]: https://github.com/miloyip
|
||||
[dtoa.h]: https://github.com/miloyip/rapidjson/blob/master/include/rapidjson/internal/dtoa.h
|
||||
[`itoa`]: https://github.com/dtolnay/itoa
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
dtoa = "0.4"
|
||||
```
|
||||
|
||||
## License
|
||||
<br>
|
||||
|
||||
Licensed under either of
|
||||
## Performance (lower is better)
|
||||
|
||||
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||
![performance](https://raw.githubusercontent.com/dtolnay/dtoa/master/performance.png)
|
||||
|
||||
at your option.
|
||||
<br>
|
||||
|
||||
### Contribution
|
||||
## Examples
|
||||
|
||||
```rust
|
||||
use std::io;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
// Write to a vector or other io::Write.
|
||||
let mut buf = Vec::new();
|
||||
dtoa::write(&mut buf, 2.71828f64)?;
|
||||
println!("{:?}", buf);
|
||||
|
||||
// Write to a stack buffer.
|
||||
let mut bytes = [b'\0'; 20];
|
||||
let n = dtoa::write(&mut bytes[..], 2.71828f64)?;
|
||||
println!("{:?}", &bytes[..n]);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
```
|
||||
|
||||
The function signature is:
|
||||
|
||||
```rust
|
||||
fn write<W: io::Write, V: dtoa::Floating>(writer: W, value: V) -> io::Result<()>;
|
||||
```
|
||||
|
||||
where `dtoa::Floating` is implemented for f32 and f64. The return value gives
|
||||
the number of bytes written.
|
||||
|
||||
<br>
|
||||
|
||||
#### License
|
||||
|
||||
<sup>
|
||||
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
|
||||
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
|
||||
</sup>
|
||||
|
||||
<br>
|
||||
|
||||
<sub>
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in dtoa by you, as defined in the Apache-2.0 license, shall be
|
||||
dual licensed as above, without any additional terms or conditions.
|
||||
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
|
||||
be dual licensed as above, without any additional terms or conditions.
|
||||
</sub>
|
||||
|
25
third_party/rust/dtoa/src/diyfp.rs
vendored
25
third_party/rust/dtoa/src/diyfp.rs
vendored
@ -1,10 +1,30 @@
|
||||
// Copyright 2016 Dtoa Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// ---
|
||||
//
|
||||
// The C++ implementation preserved here in comments is licensed as follows:
|
||||
//
|
||||
// Tencent is pleased to support the open source community by making RapidJSON
|
||||
// available.
|
||||
//
|
||||
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
|
||||
// rights reserved.
|
||||
//
|
||||
// Licensed under the MIT License (the "License"); you may not use this file
|
||||
// except in compliance with the License. You may obtain a copy of the License
|
||||
// at
|
||||
//
|
||||
// http://opensource.org/licenses/MIT
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations under
|
||||
// the License.
|
||||
|
||||
use std::ops;
|
||||
|
||||
@ -53,6 +73,7 @@ impl ops::Mul for DiyFp<u64, isize> {
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! diyfp {(
|
||||
floating_type: $fty:ty,
|
||||
|
50
third_party/rust/dtoa/src/dtoa.rs
vendored
50
third_party/rust/dtoa/src/dtoa.rs
vendored
@ -1,11 +1,32 @@
|
||||
// Copyright 2016 Dtoa Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//
|
||||
// ---
|
||||
//
|
||||
// The C++ implementation preserved here in comments is licensed as follows:
|
||||
//
|
||||
// Tencent is pleased to support the open source community by making RapidJSON
|
||||
// available.
|
||||
//
|
||||
// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
|
||||
// rights reserved.
|
||||
//
|
||||
// Licensed under the MIT License (the "License"); you may not use this file
|
||||
// except in compliance with the License. You may obtain a copy of the License
|
||||
// at
|
||||
//
|
||||
// http://opensource.org/licenses/MIT
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations under
|
||||
// the License.
|
||||
|
||||
#[doc(hidden)]
|
||||
#[macro_export]
|
||||
macro_rules! dtoa {(
|
||||
floating_type: $fty:ty,
|
||||
@ -254,11 +275,11 @@ unsafe fn write_exponent(mut k: isize, mut buffer: *mut u8) -> *mut u8 {
|
||||
if k >= 100 {
|
||||
*buffer = b'0' + (k / 100) as u8;
|
||||
k %= 100;
|
||||
let d = DEC_DIGITS_LUT.as_ptr().offset(k * 2);
|
||||
let d = DEC_DIGITS_LUT.get_unchecked(k as usize * 2);
|
||||
ptr::copy_nonoverlapping(d, buffer.offset(1), 2);
|
||||
buffer.offset(3)
|
||||
} else if k >= 10 {
|
||||
let d = DEC_DIGITS_LUT.as_ptr().offset(k * 2);
|
||||
let d = DEC_DIGITS_LUT.get_unchecked(k as usize * 2);
|
||||
ptr::copy_nonoverlapping(d, buffer, 2);
|
||||
buffer.offset(2)
|
||||
} else {
|
||||
@ -446,20 +467,27 @@ inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) {
|
||||
}
|
||||
*/
|
||||
|
||||
#[allow(deprecated)]
|
||||
#[inline]
|
||||
unsafe fn dtoa<W: io::Write>(mut wr: W, mut value: $fty) -> io::Result<usize> {
|
||||
if value == 0.0 {
|
||||
if value.is_sign_negative() {
|
||||
try!(wr.write_all(b"-0.0"));
|
||||
Ok(4)
|
||||
match wr.write_all(b"-0.0") {
|
||||
Ok(()) => Ok(4),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
} else {
|
||||
try!(wr.write_all(b"0.0"));
|
||||
Ok(3)
|
||||
match wr.write_all(b"0.0") {
|
||||
Ok(()) => Ok(3),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let negative = value < 0.0;
|
||||
if negative {
|
||||
try!(wr.write_all(b"-"));
|
||||
if let Err(e) = wr.write_all(b"-") {
|
||||
return Err(e);
|
||||
}
|
||||
value = -value;
|
||||
}
|
||||
let mut buffer: [u8; 24] = mem::uninitialized();
|
||||
@ -467,7 +495,9 @@ unsafe fn dtoa<W: io::Write>(mut wr: W, mut value: $fty) -> io::Result<usize> {
|
||||
let (length, k) = grisu2(value, buf_ptr);
|
||||
let end = prettify(buf_ptr, length, k);
|
||||
let len = end as usize - buf_ptr as usize;
|
||||
try!(wr.write_all(slice::from_raw_parts(buf_ptr, len)));
|
||||
if let Err(e) = wr.write_all(slice::from_raw_parts(buf_ptr, len)) {
|
||||
return Err(e);
|
||||
}
|
||||
if negative {
|
||||
Ok(len + 1)
|
||||
} else {
|
||||
|
87
third_party/rust/dtoa/src/lib.rs
vendored
87
third_party/rust/dtoa/src/lib.rs
vendored
@ -1,25 +1,82 @@
|
||||
// Copyright 2016 Dtoa Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
//! [![github]](https://github.com/dtolnay/dtoa) [![crates-io]](https://crates.io/crates/dtoa) [![docs-rs]](https://docs.rs/dtoa)
|
||||
//!
|
||||
//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
|
||||
//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust
|
||||
//! [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
|
||||
//!
|
||||
//! <br>
|
||||
//!
|
||||
//! This crate provides fast functions for printing floating-point primitives to
|
||||
//! an [`io::Write`]. The implementation is a straightforward Rust port of [Milo
|
||||
//! Yip]'s C++ implementation [dtoa.h]. The original C++ code of each function
|
||||
//! is included in comments.
|
||||
//!
|
||||
//! See also [`itoa`] for printing integer primitives.
|
||||
//!
|
||||
//! [`io::Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
|
||||
//! [Milo Yip]: https://github.com/miloyip
|
||||
//! [dtoa.h]: https://github.com/miloyip/rapidjson/blob/master/include/rapidjson/internal/dtoa.h
|
||||
//! [`itoa`]: https://github.com/dtolnay/itoa
|
||||
//!
|
||||
//! <br>
|
||||
//!
|
||||
//! ## Performance (lower is better)
|
||||
//!
|
||||
//! ![performance](https://raw.githubusercontent.com/dtolnay/dtoa/master/performance.png)
|
||||
//!
|
||||
//! <br>
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! ```edition2018
|
||||
//! use std::io;
|
||||
//!
|
||||
//! fn main() -> io::Result<()> {
|
||||
//! // Write to a vector or other io::Write.
|
||||
//! let mut buf = Vec::new();
|
||||
//! dtoa::write(&mut buf, 2.71828f64)?;
|
||||
//! println!("{:?}", buf);
|
||||
//!
|
||||
//! // Write to a stack buffer.
|
||||
//! let mut bytes = [b'\0'; 20];
|
||||
//! let n = dtoa::write(&mut bytes[..], 2.71828f64)?;
|
||||
//! println!("{:?}", &bytes[..n]);
|
||||
//!
|
||||
//! Ok(())
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/dtoa/0.4.2")]
|
||||
#![doc(html_root_url = "https://docs.rs/dtoa/0.4.8")]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(renamed_and_removed_lints))]
|
||||
#![cfg_attr(
|
||||
feature = "cargo-clippy",
|
||||
allow(
|
||||
cast_lossless,
|
||||
cast_possible_truncation,
|
||||
if_not_else,
|
||||
missing_errors_doc,
|
||||
range_plus_one,
|
||||
shadow_unrelated,
|
||||
transmute_float_to_int,
|
||||
unreadable_literal,
|
||||
unseparated_literal_suffix
|
||||
)
|
||||
)]
|
||||
|
||||
#[macro_use] mod diyfp;
|
||||
#[macro_use] mod dtoa;
|
||||
|
||||
use std::{io, mem, ops, ptr, slice};
|
||||
|
||||
/// Write float to an `io::Write`.
|
||||
#[inline]
|
||||
pub fn write<W: io::Write, V: Floating>(wr: W, value: V) -> io::Result<usize> {
|
||||
value.write(wr)
|
||||
}
|
||||
|
||||
/// An floating point number that can be formatted by `dtoa::write`.
|
||||
pub trait Floating {
|
||||
fn write<W: io::Write>(self, W) -> io::Result<usize>;
|
||||
fn write<W: io::Write>(self, wr: W) -> io::Result<usize>;
|
||||
}
|
||||
|
||||
impl Floating for f32 {
|
||||
@ -70,12 +127,12 @@ impl Floating for f64 {
|
||||
|
||||
const MAX_DECIMAL_PLACES: isize = 324;
|
||||
|
||||
static DEC_DIGITS_LUT: &'static [u8] =
|
||||
b"0001020304050607080910111213141516171819\
|
||||
2021222324252627282930313233343536373839\
|
||||
4041424344454647484950515253545556575859\
|
||||
6061626364656667686970717273747576777879\
|
||||
8081828384858687888990919293949596979899";
|
||||
static DEC_DIGITS_LUT: [u8; 200] = *b"\
|
||||
0001020304050607080910111213141516171819\
|
||||
2021222324252627282930313233343536373839\
|
||||
4041424344454647484950515253545556575859\
|
||||
6061626364656667686970717273747576777879\
|
||||
8081828384858687888990919293949596979899";
|
||||
|
||||
// 10^-36, 10^-28, ..., 10^52
|
||||
static CACHED_POWERS_F_32: [u32; 12] = [
|
||||
|
Loading…
Reference in New Issue
Block a user