use crate::lib::slice;
use super::algorithm::copy_to_dst;
use super::rounding::RoundingKind;
fn is_control_character(ch: u8, is_default: bool) -> bool {
if is_default {
match ch as char {
'0' ..= '9' => true,
'a' ..= 'd' => true,
'A' ..= 'D' => true,
'.' | '+' | '-' => true,
_ => false,
}
} else {
match ch as char {
'0' ..= '9' => true,
'a' ..= 'z' => true,
'A' ..= 'Z' => true,
'.' | '+' | '-' => true,
_ => false,
}
}
}
#[inline]
fn starts_with_n(bytes: &[u8]) -> bool {
match bytes.get(0) {
Some(&b'N') => true,
Some(&b'n') => true,
_ => false,
}
}
#[inline]
fn starts_with_i(bytes: &[u8]) -> bool {
match bytes.get(0) {
Some(&b'I') => true,
Some(&b'i') => true,
_ => false,
}
}
pub(crate) struct FloatConfigString {
data: [u8; F32_FORMATTED_SIZE - 1],
length: usize,
}
impl FloatConfigString {
pub(crate) fn load_bytes(&mut self, bytes: &[u8]) {
assert!(bytes.len() <= self.data.len());
copy_to_dst(&mut self.data, bytes);
self.length = bytes.len();
}
pub(crate) fn as_bytes(&self) -> &[u8] {
unsafe {
self.data.get_unchecked(..self.length)
}
}
}
static mut EXPONENT_DEFAULT_CHAR: u8 = b'e';
#[cfg(feature ="radix")]
static mut EXPONENT_BACKUP_CHAR: u8 = b'^';
#[cfg(feature = "rounding")]
static mut FLOAT_ROUNDING: RoundingKind = RoundingKind::NearestTieEven;
cfg_if! {
if #[cfg(feature = "radix")] {
static mut NAN_STRING: FloatConfigString = FloatConfigString {
data: [b'N', b'a', b'N', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0'],
length: 3
};
static mut INF_STRING: FloatConfigString = FloatConfigString {
data: [b'i', b'n', b'f', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0'],
length: 3
};
static mut INFINITY_STRING: FloatConfigString = FloatConfigString {
data: [b'i', b'n', b'f', b'i', b'n', b'i', b't', b'y', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0'],
length: 8
};
} else {
static mut NAN_STRING: FloatConfigString = FloatConfigString {
data: [b'N', b'a', b'N', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0'],
length: 3
};
static mut INF_STRING: FloatConfigString = FloatConfigString {
data: [b'i', b'n', b'f', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0'],
length: 3
};
static mut INFINITY_STRING: FloatConfigString = FloatConfigString {
data: [b'i', b'n', b'f', b'i', b'n', b'i', b't', b'y', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0', b'0'],
length: 8
};
}
}
#[inline]
pub fn get_exponent_default_char() -> u8
{
unsafe {
EXPONENT_DEFAULT_CHAR
}
}
#[inline]
pub unsafe fn set_exponent_default_char(ch: u8)
{
assert!(!is_control_character(ch, true));
EXPONENT_DEFAULT_CHAR = ch
}
#[inline]
#[cfg(feature ="radix")]
pub fn get_exponent_backup_char() -> u8
{
unsafe {
EXPONENT_BACKUP_CHAR
}
}
#[inline]
#[cfg(feature ="radix")]
pub unsafe fn set_exponent_backup_char(ch: u8)
{
assert!(!is_control_character(ch, false));
EXPONENT_BACKUP_CHAR = ch
}
#[inline]
#[cfg(feature = "rounding")]
pub fn get_float_rounding() -> RoundingKind {
unsafe {
FLOAT_ROUNDING
}
}
#[inline]
#[cfg(feature = "rounding")]
pub unsafe fn set_float_rounding(rounding: RoundingKind) {
FLOAT_ROUNDING = rounding
}
#[inline]
pub fn get_nan_string() -> &'static [u8]
{
unsafe {
NAN_STRING.as_bytes()
}
}
#[inline]
pub unsafe fn set_nan_string(bytes: &[u8])
{
assert!(starts_with_n(bytes));
NAN_STRING.load_bytes(bytes);
}
#[inline]
pub fn get_inf_string() -> &'static [u8]
{
unsafe {
INF_STRING.as_bytes()
}
}
#[inline]
pub unsafe fn set_inf_string(bytes: &[u8])
{
assert!(starts_with_i(bytes) && bytes.len() <= INFINITY_STRING.length);
INF_STRING.load_bytes(bytes);
}
#[inline]
pub fn get_infinity_string() -> &'static [u8]
{
unsafe {
INFINITY_STRING.as_bytes()
}
}
#[inline]
pub unsafe fn set_infinity_string(bytes: &[u8])
{
assert!(starts_with_i(bytes) && bytes.len() >= INF_STRING.length);
INFINITY_STRING.load_bytes(bytes);
}
pub(crate) const I8_FORMATTED_SIZE_DECIMAL: usize = 4;
pub(crate) const I16_FORMATTED_SIZE_DECIMAL: usize = 6;
pub(crate) const I32_FORMATTED_SIZE_DECIMAL: usize = 11;
pub(crate) const I64_FORMATTED_SIZE_DECIMAL: usize = 20;
pub(crate) const U8_FORMATTED_SIZE_DECIMAL: usize = 3;
pub(crate) const U16_FORMATTED_SIZE_DECIMAL: usize = 5;
pub(crate) const U32_FORMATTED_SIZE_DECIMAL: usize = 10;
pub(crate) const U64_FORMATTED_SIZE_DECIMAL: usize = 20;
pub(crate) const F32_FORMATTED_SIZE_DECIMAL: usize = 64;
pub(crate) const F64_FORMATTED_SIZE_DECIMAL: usize = 64;
pub(crate) const I128_FORMATTED_SIZE_DECIMAL: usize = 40;
pub(crate) const U128_FORMATTED_SIZE_DECIMAL: usize = 39;
cfg_if! {
if #[cfg(feature = "radix")] {
pub(crate) const I8_FORMATTED_SIZE: usize = 16;
pub(crate) const I16_FORMATTED_SIZE: usize = 32;
pub(crate) const I32_FORMATTED_SIZE: usize = 64;
pub(crate) const I64_FORMATTED_SIZE: usize = 128;
pub(crate) const U8_FORMATTED_SIZE: usize = 16;
pub(crate) const U16_FORMATTED_SIZE: usize = 32;
pub(crate) const U32_FORMATTED_SIZE: usize = 64;
pub(crate) const U64_FORMATTED_SIZE: usize = 128;
pub(crate) const F32_FORMATTED_SIZE: usize = 256;
pub(crate) const F64_FORMATTED_SIZE: usize = 256;
pub(crate) const I128_FORMATTED_SIZE: usize = 256;
pub(crate) const U128_FORMATTED_SIZE: usize = 256;
} else {
pub(crate) const I8_FORMATTED_SIZE: usize = I8_FORMATTED_SIZE_DECIMAL;
pub(crate) const I16_FORMATTED_SIZE: usize = I16_FORMATTED_SIZE_DECIMAL;
pub(crate) const I32_FORMATTED_SIZE: usize = I32_FORMATTED_SIZE_DECIMAL;
pub(crate) const I64_FORMATTED_SIZE: usize = I64_FORMATTED_SIZE_DECIMAL;
pub(crate) const U8_FORMATTED_SIZE: usize = U8_FORMATTED_SIZE_DECIMAL;
pub(crate) const U16_FORMATTED_SIZE: usize = U16_FORMATTED_SIZE_DECIMAL;
pub(crate) const U32_FORMATTED_SIZE: usize = U32_FORMATTED_SIZE_DECIMAL;
pub(crate) const U64_FORMATTED_SIZE: usize = U64_FORMATTED_SIZE_DECIMAL;
pub(crate) const F32_FORMATTED_SIZE: usize = F32_FORMATTED_SIZE_DECIMAL;
pub(crate) const F64_FORMATTED_SIZE: usize = F64_FORMATTED_SIZE_DECIMAL;
pub(crate) const I128_FORMATTED_SIZE: usize = I128_FORMATTED_SIZE_DECIMAL;
pub(crate) const U128_FORMATTED_SIZE: usize = U128_FORMATTED_SIZE_DECIMAL;
}}
cfg_if! {
if #[cfg(target_pointer_width = "16")] {
pub(crate) const ISIZE_FORMATTED_SIZE: usize = I16_FORMATTED_SIZE;
pub(crate) const ISIZE_FORMATTED_SIZE_DECIMAL: usize = I16_FORMATTED_SIZE_DECIMAL;
pub(crate) const USIZE_FORMATTED_SIZE: usize = U16_FORMATTED_SIZE;
pub(crate) const USIZE_FORMATTED_SIZE_DECIMAL: usize = U16_FORMATTED_SIZE_DECIMAL;
} else if #[cfg(target_pointer_width = "32")] {
pub(crate) const ISIZE_FORMATTED_SIZE: usize = I32_FORMATTED_SIZE;
pub(crate) const ISIZE_FORMATTED_SIZE_DECIMAL: usize = I32_FORMATTED_SIZE_DECIMAL;
pub(crate) const USIZE_FORMATTED_SIZE: usize = U32_FORMATTED_SIZE;
pub(crate) const USIZE_FORMATTED_SIZE_DECIMAL: usize = U32_FORMATTED_SIZE_DECIMAL;
} else if #[cfg(target_pointer_width = "64")] {
pub(crate) const ISIZE_FORMATTED_SIZE: usize = I64_FORMATTED_SIZE;
pub(crate) const ISIZE_FORMATTED_SIZE_DECIMAL: usize = I64_FORMATTED_SIZE_DECIMAL;
pub(crate) const USIZE_FORMATTED_SIZE: usize = U64_FORMATTED_SIZE;
pub(crate) const USIZE_FORMATTED_SIZE_DECIMAL: usize = U64_FORMATTED_SIZE_DECIMAL;
}}
pub const BUFFER_SIZE: usize = F64_FORMATTED_SIZE;
#[inline]
#[allow(unused_variables)]
pub(crate) fn exponent_notation_char(radix: u32) -> u8 {
#[cfg(not(feature ="radix"))] {
get_exponent_default_char()
}
#[cfg(feature ="radix")] {
if radix >= 15 {
get_exponent_backup_char()
} else {
get_exponent_default_char()
}
}
}
#[cfg(test)]
mod tests {
use crate::util::*;
use crate::util::test::*;
use super::*;
#[cfg(feature ="radix")]
#[test]
fn exponent_notation_char_test() {
let default = get_exponent_default_char();
let backup = get_exponent_backup_char();
assert_eq!(exponent_notation_char(2), default);
assert_eq!(exponent_notation_char(8), default);
assert_eq!(exponent_notation_char(10), default);
assert_eq!(exponent_notation_char(15), backup);
assert_eq!(exponent_notation_char(16), backup);
assert_eq!(exponent_notation_char(32), backup);
}
#[test]
#[ignore]
fn special_bytes_test() {
unsafe {
let mut buffer = new_buffer();
assert!(f32::from_lexical(b"NaN").unwrap().is_nan());
assert!(f32::from_lexical(b"nan").unwrap().is_nan());
assert!(f32::from_lexical(b"NAN").unwrap().is_nan());
assert!(f32::from_lexical(b"inf").unwrap().is_infinite());
assert!(f32::from_lexical(b"INF").unwrap().is_infinite());
assert!(f32::from_lexical(b"Infinity").unwrap().is_infinite());
assert_eq!(f64::NAN.to_lexical(&mut buffer), b"NaN");
assert_eq!(f64::INFINITY.to_lexical(&mut buffer), b"inf");
set_nan_string(b"nan");
set_inf_string(b"Infinity");
assert!(f32::from_lexical(b"inf").err().unwrap().code == ErrorCode::InvalidDigit);
assert!(f32::from_lexical(b"Infinity").unwrap().is_infinite());
assert_eq!(f64::NAN.to_lexical(&mut buffer), b"nan");
assert_eq!(f64::INFINITY.to_lexical(&mut buffer), b"Infinity");
set_nan_string(b"NaN");
set_inf_string(b"inf");
}
}
#[cfg(all(feature = "correct", feature = "rounding"))]
#[test]
#[ignore]
fn special_rounding_test() {
unsafe {
set_float_rounding(RoundingKind::NearestTieEven);
assert_eq!(f64::from_lexical(b"-9007199254740993").unwrap(), -9007199254740992.0);
assert_eq!(f64::from_lexical(b"-9007199254740995").unwrap(), -9007199254740996.0);
assert_eq!(f64::from_lexical(b"9007199254740993").unwrap(), 9007199254740992.0);
assert_eq!(f64::from_lexical(b"9007199254740995").unwrap(), 9007199254740996.0);
set_float_rounding(RoundingKind::NearestTieAwayZero);
assert_eq!(f64::from_lexical(b"-9007199254740993").unwrap(), -9007199254740994.0);
assert_eq!(f64::from_lexical(b"-9007199254740995").unwrap(), -9007199254740996.0);
assert_eq!(f64::from_lexical(b"9007199254740993").unwrap(), 9007199254740994.0);
assert_eq!(f64::from_lexical(b"9007199254740995").unwrap(), 9007199254740996.0);
set_float_rounding(RoundingKind::TowardPositiveInfinity);
assert_eq!(f64::from_lexical(b"-9007199254740993").unwrap(), -9007199254740992.0);
assert_eq!(f64::from_lexical(b"-9007199254740995").unwrap(), -9007199254740994.0);
assert_eq!(f64::from_lexical(b"9007199254740993").unwrap(), 9007199254740994.0);
assert_eq!(f64::from_lexical(b"9007199254740995").unwrap(), 9007199254740996.0);
set_float_rounding(RoundingKind::TowardNegativeInfinity);
assert_eq!(f64::from_lexical(b"-9007199254740993").unwrap(), -9007199254740994.0);
assert_eq!(f64::from_lexical(b"-9007199254740995").unwrap(), -9007199254740996.0);
assert_eq!(f64::from_lexical(b"9007199254740993").unwrap(), 9007199254740992.0);
assert_eq!(f64::from_lexical(b"9007199254740995").unwrap(), 9007199254740994.0);
set_float_rounding(RoundingKind::TowardZero);
assert_eq!(f64::from_lexical(b"-9007199254740993").unwrap(), -9007199254740992.0);
assert_eq!(f64::from_lexical(b"-9007199254740995").unwrap(), -9007199254740994.0);
assert_eq!(f64::from_lexical(b"9007199254740993").unwrap(), 9007199254740992.0);
assert_eq!(f64::from_lexical(b"9007199254740995").unwrap(), 9007199254740994.0);
set_float_rounding(RoundingKind::NearestTieEven);
}
}
#[cfg(all(feature = "correct", feature = "radix", feature = "rounding"))]
#[test]
#[ignore]
fn special_rounding_binary_test() {
unsafe {
set_float_rounding(RoundingKind::NearestTieEven);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000001", 2).unwrap(), -9007199254740992.0);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000011", 2).unwrap(), -9007199254740996.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000001", 2).unwrap(), 9007199254740992.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000011", 2).unwrap(), 9007199254740996.0);
set_float_rounding(RoundingKind::NearestTieAwayZero);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000001", 2).unwrap(), -9007199254740994.0);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000011", 2).unwrap(), -9007199254740996.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000001", 2).unwrap(), 9007199254740994.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000011", 2).unwrap(), 9007199254740996.0);
set_float_rounding(RoundingKind::TowardPositiveInfinity);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000001", 2).unwrap(), -9007199254740992.0);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000011", 2).unwrap(), -9007199254740994.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000001", 2).unwrap(), 9007199254740994.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000011", 2).unwrap(), 9007199254740996.0);
set_float_rounding(RoundingKind::TowardNegativeInfinity);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000001", 2).unwrap(), -9007199254740994.0);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000011", 2).unwrap(), -9007199254740996.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000001", 2).unwrap(), 9007199254740992.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000011", 2).unwrap(), 9007199254740994.0);
set_float_rounding(RoundingKind::TowardZero);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000001", 2).unwrap(), -9007199254740992.0);
assert_eq!(f64::from_lexical_radix(b"-100000000000000000000000000000000000000000000000000011", 2).unwrap(), -9007199254740994.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000001", 2).unwrap(), 9007199254740992.0);
assert_eq!(f64::from_lexical_radix(b"100000000000000000000000000000000000000000000000000011", 2).unwrap(), 9007199254740994.0);
set_float_rounding(RoundingKind::NearestTieEven);
}
}
#[should_panic]
#[test]
fn set_exponent_default_char_digit_test() {
unsafe {
set_exponent_default_char(b'0')
}
}
#[should_panic]
#[test]
fn set_exponent_default_char_period_test() {
unsafe {
set_exponent_default_char(b'.')
}
}
#[should_panic]
#[test]
fn set_exponent_default_char_add_test() {
unsafe {
set_exponent_default_char(b'+')
}
}
#[should_panic]
#[test]
fn set_exponent_default_char_sub_test() {
unsafe {
set_exponent_default_char(b'-')
}
}
#[cfg(all(feature = "radix"))]
#[should_panic]
#[test]
fn set_exponent_backup_char_digit_test() {
unsafe {
set_exponent_backup_char(b'0')
}
}
#[cfg(all(feature = "radix"))]
#[should_panic]
#[test]
fn set_exponent_backup_char_period_test() {
unsafe {
set_exponent_backup_char(b'.')
}
}
#[cfg(all(feature = "radix"))]
#[should_panic]
#[test]
fn set_exponent_backup_char_add_test() {
unsafe {
set_exponent_backup_char(b'+')
}
}
#[cfg(all(feature = "radix"))]
#[should_panic]
#[test]
fn set_exponent_backup_char_sub_test() {
unsafe {
set_exponent_backup_char(b'-')
}
}
#[should_panic]
#[test]
fn set_nan_string_empty_test() {
unsafe {
set_nan_string(b"")
}
}
#[should_panic]
#[test]
fn set_nan_string_invalid_test() {
unsafe {
set_nan_string(b"i")
}
}
#[should_panic]
#[test]
fn set_inf_string_empty_test() {
unsafe {
set_inf_string(b"")
}
}
#[should_panic]
#[test]
fn set_inf_string_invalid_test() {
unsafe {
set_inf_string(b"n")
}
}
#[should_panic]
#[test]
fn set_inf_string_long_test() {
unsafe {
set_inf_string(b"infinityinfinf")
}
}
#[should_panic]
#[test]
fn set_infinity_string_empty_test() {
unsafe {
set_infinity_string(b"")
}
}
#[should_panic]
#[test]
fn set_infinity_string_invalid_test() {
unsafe {
set_infinity_string(b"n")
}
}
#[should_panic]
#[test]
fn set_infinity_string_short_test() {
unsafe {
set_infinity_string(b"i")
}
}
}