Skip to content

Commit d6d224d

Browse files
committed
Attribute original code, closes #80
1 parent b825e60 commit d6d224d

File tree

6 files changed

+38
-5
lines changed

6 files changed

+38
-5
lines changed

src/codegen.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::Write;
33
use JsonValue;
44
use number::Number;
55

6-
use util::write::write;
6+
use util::print_dec;
77

88
const QU: u8 = b'"';
99
const BS: u8 = b'\\';
@@ -104,7 +104,12 @@ pub trait Generator {
104104
}
105105
let (positive, mantissa, exponent) = num.as_parts();
106106
unsafe {
107-
write(self.get_writer(), positive, mantissa, exponent).unwrap();
107+
print_dec::write(
108+
self.get_writer(),
109+
positive,
110+
mantissa,
111+
exponent
112+
).unwrap();
108113
}
109114
}
110115

src/number.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{ ops, fmt, f32, f64 };
22
use std::num::FpCategory;
33
use util::grisu2;
4-
use util::write::write;
4+
use util::print_dec;
55

66
/// NaN value represented in `Number` type. NaN is equal to itself.
77
pub const NAN: Number = Number {
@@ -203,7 +203,7 @@ impl fmt::Display for Number {
203203
}
204204
let (positive, mantissa, exponent) = self.as_parts();
205205
let mut buf = Vec::new();
206-
write(&mut buf, positive, mantissa, exponent).unwrap();
206+
print_dec::write(&mut buf, positive, mantissa, exponent).unwrap();
207207
f.write_str(&String::from_utf8_unchecked(buf))
208208
}
209209
}

src/util/diyfp.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// This file comes from the `dtoa` port by David Tolnay:
2+
// https://github.com/dtolnay/dtoa
3+
//
14
// Copyright 2016 Dtoa Developers
25
//
36
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or

src/util/grisu2.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
// This file comes from the `dtoa` port by David Tolnay:
2+
// https://github.com/dtolnay/dtoa
3+
//
4+
// It's an implementation of a Grisu2 algorithm by Florian Loitsch:
5+
// http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
6+
//
7+
// The algorithm here has been modified to produce a `u64` mantisa and
8+
// a decimal exponent instead of writing to a string.
9+
//
10+
// Copyright 2016 Dtoa Developers
11+
//
12+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
13+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
14+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
15+
// option. This file may not be copied, modified, or distributed
16+
// except according to those terms.
17+
118
use util::diyfp::{ self, DiyFp };
219

320
#[inline]

src/util/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod diyfp;
22
pub mod grisu2;
3-
pub mod write;
3+
pub mod print_dec;

src/util/write.rs renamed to src/util/print_dec.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
// This is a modified version of the `itoa` crate by David Tolnay:
2+
// https://github.com/dtolnay/itoa
3+
//
4+
// The crate itself borrows code from the stdlib of Rust.
5+
//
6+
// The algorithm here was modified from being able to just writing integers,
7+
// to printing decimal floating points.
8+
19
use std::{io, mem, ptr, slice};
210

311
const DEC_DIGITS_LUT: &'static[u8] =

0 commit comments

Comments
 (0)