// Translated from C to Rust. The original C code can be found at // https://github.com/ulfjack/ryu and carries the following license: // // Copyright 2018 Ulf Adams // // The contents of this file may be used under the terms of the Apache License, // Version 2.0. // // (See accompanying file LICENSE-Apache or copy at // http://www.apache.org/licenses/LICENSE-2.0) // // Alternatively, the contents of this file may be used under the terms of // the Boost Software License, Version 1.0. // (See accompanying file LICENSE-Boost or copy at // https://www.boost.org/LICENSE_1_0.txt) // // Unless required by applicable law or agreed to in writing, this software // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied.
#[test] fn test_mantissa_rounding_overflow() { // This results in binary mantissa that is all ones and requires rounding up // because it is closer to 1 than to the next smaller float. This is a // regression test that the mantissa overflow is handled correctly by // increasing the exponent.
assert_eq!(1.0, s2d(b"0.99999999999999999").unwrap()); // This number overflows the mantissa *and* the IEEE exponent.
assert_eq!(f64::INFINITY, s2d(b"1.7976931348623159e308").unwrap());
}
#[test] fn test_underflow() {
assert_eq!(0.0, s2d(b"2.4e-324").unwrap());
assert_eq!(0.0, s2d(b"1e-324").unwrap());
assert_eq!(0.0, s2d(b"9.99999e-325").unwrap()); // These are just about halfway between 0 and the smallest float. // The first is just below the halfway point, the second just above.
assert_eq!(0.0, s2d(b"2.4703282292062327e-324").unwrap());
assert_eq!(5e-324, s2d(b"2.4703282292062328e-324").unwrap());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.