use core::cmp::Ordering::{self, *};
use malachite_base::num::arithmetic::traits::{PowerOf2, Sinh, SinhAssign};
use malachite_base::num::basic::floats::PrimitiveFloat;
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, One, Zero,
};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_base::num::conversion::traits::{ExactFrom, RoundingFrom};
use malachite_base::num::float::NiceFloat;
use malachite_base::num::logic::traits::SignificantBits;
use malachite_base::rounding_modes::RoundingMode::{self, *};
use malachite_base::rounding_modes::exhaustive::exhaustive_rounding_modes;
use malachite_base::test_util::generators::{
primitive_float_gen, unsigned_rounding_mode_pair_gen_var_3,
};
use malachite_float::float::arithmetic::sinh::{
primitive_float_sinh, primitive_float_sinh_rational,
};
use malachite_float::test_util::common::{
assert_rounding_ordering_consistent, parse_hex_string, round_once_to_primitive,
rug_round_try_from_rounding_mode, to_hex_string,
};
use malachite_float::test_util::float::arithmetic::sinh::{
rug_sinh, rug_sinh_prec, rug_sinh_prec_round, rug_sinh_rational_prec,
rug_sinh_rational_prec_round, rug_sinh_round,
};
use malachite_float::test_util::generators::{
float_gen, float_rounding_mode_pair_gen_var_47, float_unsigned_pair_gen_var_1,
float_unsigned_rounding_mode_triple_gen_var_36,
rational_unsigned_rounding_mode_triple_gen_var_10,
};
use malachite_float::{ComparableFloat, ComparableFloatRef, Float};
use malachite_q::Rational;
use malachite_q::test_util::generators::{rational_gen, rational_unsigned_pair_gen_var_3};
use std::panic::catch_unwind;
use std::str::FromStr;
#[test]
fn test_sinh_prec_round() {
let test = |s, s_hex, prec: u64, rm, out: &str, out_hex: &str, o_out: Ordering| {
let x = parse_hex_string(s_hex);
assert_eq!(x.to_string(), s);
let (c, o) = x.clone().sinh_prec_round(prec, rm);
assert!(c.is_valid());
assert_eq!(c.to_string(), out);
assert_eq!(to_hex_string(&c), out_hex);
assert_eq!(o, o_out);
let (c_alt, o_alt) = x.sinh_prec_round_ref(prec, rm);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut c_alt = x.clone();
let o_alt = c_alt.sinh_prec_round_assign(prec, rm);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if let Ok(rug_rm) = rug_round_try_from_rounding_mode(rm) {
let (rug_c, rug_o) = rug_sinh_prec_round(&rug::Float::exact_from(&x), prec, rug_rm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
};
test("NaN", "NaN", 1, Nearest, "NaN", "NaN", Equal);
test(
"Infinity", "Infinity", 1, Nearest, "Infinity", "Infinity", Equal,
);
test(
"-Infinity",
"-Infinity",
1,
Nearest,
"-Infinity",
"-Infinity",
Equal,
);
test("0.0", "0x0.0", 1, Nearest, "0.0", "0x0.0", Equal);
test("-0.0", "-0x0.0", 1, Nearest, "-0.0", "-0x0.0", Equal);
test("0.0", "0x0.0", 10, Nearest, "0.0", "0x0.0", Equal);
test("1.0", "0x1.0#1", 1, Floor, "1.0", "0x1.0#1", Less);
test("1.0", "0x1.0#1", 1, Ceiling, "2.0", "0x2.0#1", Greater);
test("1.0", "0x1.0#1", 1, Nearest, "1.0", "0x1.0#1", Less);
test("1.0", "0x1.0#1", 10, Floor, "1.1738", "0x1.2c8#10", Less);
test(
"1.0",
"0x1.0#1",
10,
Ceiling,
"1.1758",
"0x1.2d0#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
10,
Nearest,
"1.1758",
"0x1.2d0#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
100,
Floor,
"1.1752011936438014568823818505953",
"0x1.2cd9fc44eb9825a80249487f0#100",
Less,
);
test(
"1.0",
"0x1.0#1",
100,
Ceiling,
"1.1752011936438014568823818505969",
"0x1.2cd9fc44eb9825a80249487f2#100",
Greater,
);
test(
"1.0",
"0x1.0#1",
100,
Nearest,
"1.1752011936438014568823818505953",
"0x1.2cd9fc44eb9825a80249487f0#100",
Less,
);
test(
"-1.0",
"-0x1.0#1",
10,
Floor,
"-1.1758",
"-0x1.2d0#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
10,
Ceiling,
"-1.1738",
"-0x1.2c8#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
10,
Nearest,
"-1.1758",
"-0x1.2d0#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
100,
Floor,
"-1.1752011936438014568823818505969",
"-0x1.2cd9fc44eb9825a80249487f2#100",
Less,
);
test(
"-1.0",
"-0x1.0#1",
100,
Ceiling,
"-1.1752011936438014568823818505953",
"-0x1.2cd9fc44eb9825a80249487f0#100",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
100,
Nearest,
"-1.1752011936438014568823818505953",
"-0x1.2cd9fc44eb9825a80249487f0#100",
Greater,
);
test("0.50", "0x0.8#1", 10, Floor, "0.52051", "0x0.854#10", Less);
test(
"0.50",
"0x0.8#1",
10,
Ceiling,
"0.52148",
"0x0.858#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
10,
Nearest,
"0.52148",
"0x0.858#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
100,
Floor,
"0.52109530549374736162242562641114",
"0x0.8566807f31dcb651abc4abb0d#100",
Less,
);
test(
"0.50",
"0x0.8#1",
100,
Ceiling,
"0.52109530549374736162242562641193",
"0x0.8566807f31dcb651abc4abb0e#100",
Greater,
);
test(
"0.50",
"0x0.8#1",
100,
Nearest,
"0.52109530549374736162242562641114",
"0x0.8566807f31dcb651abc4abb0d#100",
Less,
);
test(
"-0.50",
"-0x0.8#1",
10,
Floor,
"-0.52148",
"-0x0.858#10",
Less,
);
test(
"-0.50",
"-0x0.8#1",
10,
Ceiling,
"-0.52051",
"-0x0.854#10",
Greater,
);
test(
"-0.50",
"-0x0.8#1",
10,
Nearest,
"-0.52148",
"-0x0.858#10",
Less,
);
test(
"-0.50",
"-0x0.8#1",
100,
Floor,
"-0.52109530549374736162242562641193",
"-0x0.8566807f31dcb651abc4abb0e#100",
Less,
);
test(
"-0.50",
"-0x0.8#1",
100,
Ceiling,
"-0.52109530549374736162242562641114",
"-0x0.8566807f31dcb651abc4abb0d#100",
Greater,
);
test(
"-0.50",
"-0x0.8#1",
100,
Nearest,
"-0.52109530549374736162242562641114",
"-0x0.8566807f31dcb651abc4abb0d#100",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Floor,
"0.33936",
"0x0.56e#10",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Ceiling,
"0.33984",
"0x0.570#10",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Nearest,
"0.33936",
"0x0.56e#10",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Floor,
"0.33954055725615013910126061133846",
"0x0.56ec214514ae05405cea1145d0#100",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Ceiling,
"0.33954055725615013910126061133886",
"0x0.56ec214514ae05405cea1145d8#100",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Nearest,
"0.33954055725615013910126061133886",
"0x0.56ec214514ae05405cea1145d8#100",
Greater,
);
test("2.0", "0x2.0#2", 10, Floor, "3.6250", "0x3.a0#10", Less);
test(
"2.0",
"0x2.0#2",
10,
Ceiling,
"3.6289",
"0x3.a1#10",
Greater,
);
test("2.0", "0x2.0#2", 10, Nearest, "3.6250", "0x3.a0#10", Less);
test(
"2.0",
"0x2.0#2",
100,
Floor,
"3.6268604078470187676682139828013",
"0x3.a079ec76dc33ede69900592c4#100",
Less,
);
test(
"2.0",
"0x2.0#2",
100,
Ceiling,
"3.6268604078470187676682139828044",
"0x3.a079ec76dc33ede69900592c8#100",
Greater,
);
test(
"2.0",
"0x2.0#2",
100,
Nearest,
"3.6268604078470187676682139828013",
"0x3.a079ec76dc33ede69900592c4#100",
Less,
);
test(
"10.0",
"0xa.0#4",
10,
Floor,
"11008.0",
"0x2.b0E+3#10",
Less,
);
test(
"10.0",
"0xa.0#4",
10,
Ceiling,
"11024.0",
"0x2.b1E+3#10",
Greater,
);
test(
"10.0",
"0xa.0#4",
10,
Nearest,
"11008.0",
"0x2.b0E+3#10",
Less,
);
test(
"10.0",
"0xa.0#4",
100,
Floor,
"11013.232874703393377236524554834",
"0x2b05.3b9dad3323e7c80b6e4524#100",
Less,
);
test(
"10.0",
"0xa.0#4",
100,
Ceiling,
"11013.232874703393377236524554847",
"0x2b05.3b9dad3323e7c80b6e4528#100",
Greater,
);
test(
"10.0",
"0xa.0#4",
100,
Nearest,
"11013.232874703393377236524554847",
"0x2b05.3b9dad3323e7c80b6e4528#100",
Greater,
);
test(
"-100.0",
"-0x64.0#7",
10,
Floor,
"-1.3459e43",
"-0x9.a8E+35#10",
Less,
);
test(
"-100.0",
"-0x64.0#7",
10,
Ceiling,
"-1.3437e43",
"-0x9.a4E+35#10",
Greater,
);
test(
"-100.0",
"-0x64.0#7",
10,
Nearest,
"-1.3437e43",
"-0x9.a4E+35#10",
Greater,
);
test(
"-100.0",
"-0x64.0#7",
100,
Floor,
"-1.3440585709080677242063127757915e43",
"-0x9.a4a54d8b8dfa566112849992E+35#100",
Less,
);
test(
"-100.0",
"-0x64.0#7",
100,
Ceiling,
"-1.3440585709080677242063127757898e43",
"-0x9.a4a54d8b8dfa566112849991E+35#100",
Greater,
);
test(
"-100.0",
"-0x64.0#7",
100,
Nearest,
"-1.3440585709080677242063127757898e43",
"-0x9.a4a54d8b8dfa566112849991E+35#100",
Greater,
);
test(
"1000.0",
"0x3e8.0#10",
10,
Floor,
"9.8398e433",
"0x3.3cE+360#10",
Less,
);
test(
"1000.0",
"0x3e8.0#10",
10,
Ceiling,
"9.8516e433",
"0x3.3dE+360#10",
Greater,
);
test(
"1000.0",
"0x3e8.0#10",
10,
Nearest,
"9.8516e433",
"0x3.3dE+360#10",
Greater,
);
test(
"1000.0",
"0x3e8.0#10",
100,
Floor,
"9.8503555700852349694443967612105e433",
"0x3.3ce46f35dae75b00ac567f544E+360#100",
Less,
);
test(
"1000.0",
"0x3e8.0#10",
100,
Ceiling,
"9.8503555700852349694443967612201e433",
"0x3.3ce46f35dae75b00ac567f548E+360#100",
Greater,
);
test(
"1000.0",
"0x3e8.0#10",
100,
Nearest,
"9.8503555700852349694443967612201e433",
"0x3.3ce46f35dae75b00ac567f548E+360#100",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Floor,
"11.547",
"0xb.8c#10",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Ceiling,
"11.562",
"0xb.90#10",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Nearest,
"11.547",
"0xb.8c#10",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Floor,
"11.548739357257748378558851329885",
"0xb.8c7a2eb97339113d35fcbd32#100",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Ceiling,
"11.548739357257748378558851329897",
"0xb.8c7a2eb97339113d35fcbd33#100",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Nearest,
"11.548739357257748378558851329885",
"0xb.8c7a2eb97339113d35fcbd32#100",
Less,
);
test(
"1000000.0",
"0xf4240.0#20",
10,
Floor,
"1.5145e434294",
"0x4.1cE+360673#10",
Less,
);
test(
"1000000.0",
"0xf4240.0#20",
10,
Ceiling,
"1.5174e434294",
"0x4.1eE+360673#10",
Greater,
);
test(
"1000000.0",
"0xf4240.0#20",
10,
Nearest,
"1.5174e434294",
"0x4.1eE+360673#10",
Greater,
);
test(
"1000000.0",
"0xf4240.0#20",
100,
Floor,
"1.5166076984010437725432010707070e434294",
"0x4.1d6ffdeb8a9180f8c69cf6168E+360673#100",
Less,
);
test(
"1000000.0",
"0xf4240.0#20",
100,
Ceiling,
"1.5166076984010437725432010707093e434294",
"0x4.1d6ffdeb8a9180f8c69cf6170E+360673#100",
Greater,
);
test(
"1000000.0",
"0xf4240.0#20",
100,
Nearest,
"1.5166076984010437725432010707093e434294",
"0x4.1d6ffdeb8a9180f8c69cf6170E+360673#100",
Greater,
);
test(
"-100000000.0",
"-0x5f5e100.0#27",
10,
Floor,
"-7.7564e43429447",
"-0x8.84E+36067375#10",
Less,
);
test(
"-100000000.0",
"-0x5f5e100.0#27",
10,
Ceiling,
"-7.7422e43429447",
"-0x8.80E+36067375#10",
Greater,
);
test(
"-100000000.0",
"-0x5f5e100.0#27",
10,
Nearest,
"-7.7564e43429447",
"-0x8.84E+36067375#10",
Less,
);
test(
"-100000000.0",
"-0x5f5e100.0#27",
100,
Floor,
"-7.7498837332421325220922927166788e43429447",
"-0x8.8229c7cd3e3c8988ae5d5230E+36067375#100",
Less,
);
test(
"-100000000.0",
"-0x5f5e100.0#27",
100,
Ceiling,
"-7.7498837332421325220922927166673e43429447",
"-0x8.8229c7cd3e3c8988ae5d522fE+36067375#100",
Greater,
);
test(
"-100000000.0",
"-0x5f5e100.0#27",
100,
Nearest,
"-7.7498837332421325220922927166673e43429447",
"-0x8.8229c7cd3e3c8988ae5d522fE+36067375#100",
Greater,
);
test(
"0.00098",
"0x0.004#1",
10,
Floor,
"0.00097656",
"0x0.00400#10",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Floor,
"-0.00097847",
"-0x0.00402#10",
Less,
);
test(
"0.00098",
"0x0.004#1",
10,
Ceiling,
"0.00097847",
"0x0.00402#10",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Ceiling,
"-0.00097656",
"-0x0.00400#10",
Greater,
);
test(
"0.00098",
"0x0.004#1",
10,
Nearest,
"0.00097656",
"0x0.00400#10",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Nearest,
"-0.00097656",
"-0x0.00400#10",
Greater,
);
test(
"0.00098",
"0x0.004#1",
10,
Down,
"0.00097656",
"0x0.00400#10",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Down,
"-0.00097656",
"-0x0.00400#10",
Greater,
);
test(
"0.00098",
"0x0.004#1",
10,
Up,
"0.00097847",
"0x0.00402#10",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Up,
"-0.00097847",
"-0x0.00402#10",
Less,
);
test(
"0.00098",
"0x0.004#1",
100,
Floor,
"0.00097656265522043650406675150063800",
"0x0.00400000aaaaab33333367367370#100",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Floor,
"-0.00097656265522043650406675150063955",
"-0x0.00400000aaaaab33333367367378#100",
Less,
);
test(
"0.00098",
"0x0.004#1",
100,
Ceiling,
"0.00097656265522043650406675150063955",
"0x0.00400000aaaaab33333367367378#100",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Ceiling,
"-0.00097656265522043650406675150063800",
"-0x0.00400000aaaaab33333367367370#100",
Greater,
);
test(
"0.00098",
"0x0.004#1",
100,
Nearest,
"0.00097656265522043650406675150063800",
"0x0.00400000aaaaab33333367367370#100",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Nearest,
"-0.00097656265522043650406675150063800",
"-0x0.00400000aaaaab33333367367370#100",
Greater,
);
test(
"0.00098",
"0x0.004#1",
100,
Down,
"0.00097656265522043650406675150063800",
"0x0.00400000aaaaab33333367367370#100",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Down,
"-0.00097656265522043650406675150063800",
"-0x0.00400000aaaaab33333367367370#100",
Greater,
);
test(
"0.00098",
"0x0.004#1",
100,
Up,
"0.00097656265522043650406675150063955",
"0x0.00400000aaaaab33333367367378#100",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Up,
"-0.00097656265522043650406675150063955",
"-0x0.00400000aaaaab33333367367378#100",
Less,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Floor,
"8.8817841970012523233890533447266e-16",
"0x4.0000000000000000000000000E-13#100",
Less,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Floor,
"-8.8817841970012523233890533447406e-16",
"-0x4.0000000000000000000000008E-13#100",
Less,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Ceiling,
"8.8817841970012523233890533447406e-16",
"0x4.0000000000000000000000008E-13#100",
Greater,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Ceiling,
"-8.8817841970012523233890533447266e-16",
"-0x4.0000000000000000000000000E-13#100",
Greater,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Nearest,
"8.8817841970012523233890533447266e-16",
"0x4.0000000000000000000000000E-13#100",
Less,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Nearest,
"-8.8817841970012523233890533447266e-16",
"-0x4.0000000000000000000000000E-13#100",
Greater,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Down,
"8.8817841970012523233890533447266e-16",
"0x4.0000000000000000000000000E-13#100",
Less,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Down,
"-8.8817841970012523233890533447266e-16",
"-0x4.0000000000000000000000000E-13#100",
Greater,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Up,
"8.8817841970012523233890533447406e-16",
"0x4.0000000000000000000000008E-13#100",
Greater,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Up,
"-8.8817841970012523233890533447406e-16",
"-0x4.0000000000000000000000008E-13#100",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Floor,
"7.8886e-31",
"0x1.000E-25#10",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Floor,
"-7.9040e-31",
"-0x1.008E-25#10",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Ceiling,
"7.9040e-31",
"0x1.008E-25#10",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Ceiling,
"-7.8886e-31",
"-0x1.000E-25#10",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Nearest,
"7.8886e-31",
"0x1.000E-25#10",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Nearest,
"-7.8886e-31",
"-0x1.000E-25#10",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Down,
"7.8886e-31",
"0x1.000E-25#10",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Down,
"-7.8886e-31",
"-0x1.000E-25#10",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Up,
"7.9040e-31",
"0x1.008E-25#10",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Up,
"-7.9040e-31",
"-0x1.008E-25#10",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Floor,
"7.888609052210118054117285652827862296732064351090230047702790124822869216287758849295325\
8285e-31",
"0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaaaE-25#300",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Floor,
"-7.88860905221011805411728565282786229673206435109023004770279012482286921628775884929532\
58362e-31",
"-0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaacE-25#300",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Ceiling,
"7.888609052210118054117285652827862296732064351090230047702790124822869216287758849295325\
8362e-31",
"0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaacE-25#300",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Ceiling,
"-7.88860905221011805411728565282786229673206435109023004770279012482286921628775884929532\
58285e-31",
"-0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaaaE-25#300",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Nearest,
"7.888609052210118054117285652827862296732064351090230047702790124822869216287758849295325\
8285e-31",
"0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaaaE-25#300",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Nearest,
"-7.88860905221011805411728565282786229673206435109023004770279012482286921628775884929532\
58285e-31",
"-0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaaaE-25#300",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Down,
"7.888609052210118054117285652827862296732064351090230047702790124822869216287758849295325\
8285e-31",
"0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaaaE-25#300",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Down,
"-7.88860905221011805411728565282786229673206435109023004770279012482286921628775884929532\
58285e-31",
"-0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaaaE-25#300",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Up,
"7.888609052210118054117285652827862296732064351090230047702790124822869216287758849295325\
8362e-31",
"0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaacE-25#300",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Up,
"-7.88860905221011805411728565282786229673206435109023004770279012482286921628775884929532\
58362e-31",
"-0x1.000000000000000000000000000000000000000000000000002aaaaaaaaaaaaaaaaaaaaaaacE-25#300",
Less,
);
test(
"9.0949470177292823791503906250000000000000000000000000000000000e-13",
"0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Floor,
"9.0949e-13",
"0x1.000E-10#10",
Less,
);
test(
"-9.0949470177292823791503906250000000000000000000000000000000000e-13",
"-0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Floor,
"-9.1127e-13",
"-0x1.008E-10#10",
Less,
);
test(
"9.0949470177292823791503906250000000000000000000000000000000000e-13",
"0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Ceiling,
"9.1127e-13",
"0x1.008E-10#10",
Greater,
);
test(
"-9.0949470177292823791503906250000000000000000000000000000000000e-13",
"-0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Ceiling,
"-9.0949e-13",
"-0x1.000E-10#10",
Greater,
);
test(
"9.0949470177292823791503906250000000000000000000000000000000000e-13",
"0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Nearest,
"9.0949e-13",
"0x1.000E-10#10",
Less,
);
test(
"-9.0949470177292823791503906250000000000000000000000000000000000e-13",
"-0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Nearest,
"-9.0949e-13",
"-0x1.000E-10#10",
Greater,
);
test(
"9.0949470177292823791503906250000000000000000000000000000000000e-13",
"0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Down,
"9.0949e-13",
"0x1.000E-10#10",
Less,
);
test(
"-9.0949470177292823791503906250000000000000000000000000000000000e-13",
"-0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Down,
"-9.0949e-13",
"-0x1.000E-10#10",
Greater,
);
test(
"9.0949470177292823791503906250000000000000000000000000000000000e-13",
"0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Up,
"9.1127e-13",
"0x1.008E-10#10",
Greater,
);
test(
"-9.0949470177292823791503906250000000000000000000000000000000000e-13",
"-0x1.00000000000000000000000000000000000000000000000000E-10#200",
10,
Up,
"-9.1127e-13",
"-0x1.008E-10#10",
Less,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Floor,
"2.38256490488795107322e-323228497",
"0x1.0000000000000000E-268435456#64",
Less,
);
test(
"-2.4e-323228497",
"-0x1.0E-268435456#1",
64,
Floor,
"-2.38256490488795107347e-323228497",
"-0x1.0000000000000002E-268435456#64",
Less,
);
test(
"1.0e-301030",
"0x1.0E-250000#1",
64,
Floor,
"1.01003405919803022470e-301030",
"0x1.0000000000000000E-250000#64",
Less,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Ceiling,
"2.38256490488795107347e-323228497",
"0x1.0000000000000002E-268435456#64",
Greater,
);
test(
"-2.4e-323228497",
"-0x1.0E-268435456#1",
64,
Ceiling,
"-2.38256490488795107322e-323228497",
"-0x1.0000000000000000E-268435456#64",
Greater,
);
test(
"1.0e-301030",
"0x1.0E-250000#1",
64,
Ceiling,
"1.01003405919803022481e-301030",
"0x1.0000000000000002E-250000#64",
Greater,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Nearest,
"2.38256490488795107322e-323228497",
"0x1.0000000000000000E-268435456#64",
Less,
);
test(
"-2.4e-323228497",
"-0x1.0E-268435456#1",
64,
Nearest,
"-2.38256490488795107322e-323228497",
"-0x1.0000000000000000E-268435456#64",
Greater,
);
test(
"1.0e-301030",
"0x1.0E-250000#1",
64,
Nearest,
"1.01003405919803022470e-301030",
"0x1.0000000000000000E-250000#64",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Floor,
"1.0744e304006137",
"0xc.50E+252471631#10",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Ceiling,
"1.0758e304006137",
"0xc.54E+252471631#10",
Greater,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Nearest,
"1.0744e304006137",
"0xc.50E+252471631#10",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Down,
"1.0744e304006137",
"0xc.50E+252471631#10",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Up,
"1.0758e304006137",
"0xc.54E+252471631#10",
Greater,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Floor,
"1.0745986328169899684213985210251e304006137",
"0xc.507c7e17bca36323b1e8bc08E+252471631#100",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Ceiling,
"1.0745986328169899684213985210262e304006137",
"0xc.507c7e17bca36323b1e8bc09E+252471631#100",
Greater,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Nearest,
"1.0745986328169899684213985210251e304006137",
"0xc.507c7e17bca36323b1e8bc08E+252471631#100",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Down,
"1.0745986328169899684213985210251e304006137",
"0xc.507c7e17bca36323b1e8bc08E+252471631#100",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Up,
"1.0745986328169899684213985210262e304006137",
"0xc.507c7e17bca36323b1e8bc09E+252471631#100",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Floor,
"1.3301e323228496",
"0x5.12E+268435455#10",
Less,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Ceiling,
"1.3321e323228496",
"0x5.14E+268435455#10",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Nearest,
"1.3321e323228496",
"0x5.14E+268435455#10",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Down,
"1.3301e323228496",
"0x5.12E+268435455#10",
Less,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Up,
"1.3321e323228496",
"0x5.14E+268435455#10",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Floor,
"1.3315814500369112065268344141958e323228496",
"0x5.137d0b40cdfb4457d4a570f10E+268435455#100",
Less,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Ceiling,
"1.3315814500369112065268344141975e323228496",
"0x5.137d0b40cdfb4457d4a570f18E+268435455#100",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Nearest,
"1.3315814500369112065268344141975e323228496",
"0x5.137d0b40cdfb4457d4a570f18E+268435455#100",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Down,
"1.3315814500369112065268344141958e323228496",
"0x5.137d0b40cdfb4457d4a570f10E+268435455#100",
Less,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Up,
"1.3315814500369112065268344141975e323228496",
"0x5.137d0b40cdfb4457d4a570f18E+268435455#100",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Floor,
"-1.3321e323228496",
"-0x5.14E+268435455#10",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Ceiling,
"-1.3301e323228496",
"-0x5.12E+268435455#10",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Nearest,
"-1.3321e323228496",
"-0x5.14E+268435455#10",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Down,
"-1.3301e323228496",
"-0x5.12E+268435455#10",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Up,
"-1.3321e323228496",
"-0x5.14E+268435455#10",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Floor,
"-1.3315814500369112065268344141975e323228496",
"-0x5.137d0b40cdfb4457d4a570f18E+268435455#100",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Ceiling,
"-1.3315814500369112065268344141958e323228496",
"-0x5.137d0b40cdfb4457d4a570f10E+268435455#100",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Nearest,
"-1.3315814500369112065268344141975e323228496",
"-0x5.137d0b40cdfb4457d4a570f18E+268435455#100",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Down,
"-1.3315814500369112065268344141958e323228496",
"-0x5.137d0b40cdfb4457d4a570f10E+268435455#100",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Up,
"-1.3315814500369112065268344141975e323228496",
"-0x5.137d0b40cdfb4457d4a570f18E+268435455#100",
Less,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
10,
Floor,
"1.9859e323228496",
"0x7.92E+268435455#10",
Less,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
10,
Ceiling,
"1.9879e323228496",
"0x7.94E+268435455#10",
Greater,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
10,
Nearest,
"1.9879e323228496",
"0x7.94E+268435455#10",
Greater,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
10,
Down,
"1.9859e323228496",
"0x7.92E+268435455#10",
Less,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
10,
Up,
"1.9879e323228496",
"0x7.94E+268435455#10",
Greater,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
100,
Floor,
"1.9872622167931390381615986861180e323228496",
"0x7.935dcb7045691ebed3cf12138E+268435455#100",
Less,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
100,
Ceiling,
"1.9872622167931390381615986861197e323228496",
"0x7.935dcb7045691ebed3cf12140E+268435455#100",
Greater,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
100,
Nearest,
"1.9872622167931390381615986861180e323228496",
"0x7.935dcb7045691ebed3cf12138E+268435455#100",
Less,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
100,
Down,
"1.9872622167931390381615986861180e323228496",
"0x7.935dcb7045691ebed3cf12138E+268435455#100",
Less,
);
test(
"744261117.90039",
"0x2c5c85fd.e68#40",
100,
Up,
"1.9872622167931390381615986861197e323228496",
"0x7.935dcb7045691ebed3cf12140E+268435455#100",
Greater,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
10,
Floor,
"2.0965e323228496",
"0x7.feE+268435455#10",
Less,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
10,
Ceiling,
"Infinity",
"Infinity",
Greater,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
10,
Nearest,
"Infinity",
"Infinity",
Greater,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
10,
Down,
"2.0965e323228496",
"0x7.feE+268435455#10",
Less,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
10,
Up,
"Infinity",
"Infinity",
Greater,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
100,
Floor,
"2.0985787164673876924043581168822e323228496",
"0x7.ffffffffffffffffffffffff8E+268435455#100",
Less,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
100,
Ceiling,
"Infinity",
"Infinity",
Greater,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
100,
Nearest,
"Infinity",
"Infinity",
Greater,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
100,
Down,
"2.0985787164673876924043581168822e323228496",
"0x7.ffffffffffffffffffffffff8E+268435455#100",
Less,
);
test(
"744261118.00",
"0x2c5c85fe.0#30",
100,
Up,
"Infinity",
"Infinity",
Greater,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
10,
Floor,
"-Infinity",
"-Infinity",
Less,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
10,
Ceiling,
"-2.0965e323228496",
"-0x7.feE+268435455#10",
Greater,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
10,
Nearest,
"-Infinity",
"-Infinity",
Less,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
10,
Down,
"-2.0965e323228496",
"-0x7.feE+268435455#10",
Greater,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
10,
Up,
"-Infinity",
"-Infinity",
Less,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
100,
Floor,
"-Infinity",
"-Infinity",
Less,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
100,
Ceiling,
"-2.0985787164673876924043581168822e323228496",
"-0x7.ffffffffffffffffffffffff8E+268435455#100",
Greater,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
100,
Nearest,
"-Infinity",
"-Infinity",
Less,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
100,
Down,
"-2.0985787164673876924043581168822e323228496",
"-0x7.ffffffffffffffffffffffff8E+268435455#100",
Greater,
);
test(
"-744261118.00",
"-0x2c5c85fe.0#30",
100,
Up,
"-Infinity",
"-Infinity",
Less,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
10,
Floor,
"2.0965e323228496",
"0x7.feE+268435455#10",
Less,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
10,
Ceiling,
"Infinity",
"Infinity",
Greater,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
10,
Nearest,
"Infinity",
"Infinity",
Greater,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
10,
Down,
"2.0965e323228496",
"0x7.feE+268435455#10",
Less,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
10,
Up,
"Infinity",
"Infinity",
Greater,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
100,
Floor,
"2.0985787164673876924043581168822e323228496",
"0x7.ffffffffffffffffffffffff8E+268435455#100",
Less,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
100,
Ceiling,
"Infinity",
"Infinity",
Greater,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
100,
Nearest,
"Infinity",
"Infinity",
Greater,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
100,
Down,
"2.0985787164673876924043581168822e323228496",
"0x7.ffffffffffffffffffffffff8E+268435455#100",
Less,
);
test(
"1000000000.0",
"0x3b9aca00.0#30",
100,
Up,
"Infinity",
"Infinity",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Floor,
"2.0965e323228496",
"0x7.feE+268435455#10",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Ceiling,
"Infinity",
"Infinity",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Nearest,
"Infinity",
"Infinity",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Down,
"2.0965e323228496",
"0x7.feE+268435455#10",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Up,
"Infinity",
"Infinity",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Floor,
"2.0985787164673876924043581168822e323228496",
"0x7.ffffffffffffffffffffffff8E+268435455#100",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Ceiling,
"Infinity",
"Infinity",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Nearest,
"Infinity",
"Infinity",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Down,
"2.0985787164673876924043581168822e323228496",
"0x7.ffffffffffffffffffffffff8E+268435455#100",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Up,
"Infinity",
"Infinity",
Greater,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
10,
Floor,
"-Infinity",
"-Infinity",
Less,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
10,
Ceiling,
"-2.0965e323228496",
"-0x7.feE+268435455#10",
Greater,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
10,
Nearest,
"-Infinity",
"-Infinity",
Less,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
10,
Down,
"-2.0965e323228496",
"-0x7.feE+268435455#10",
Greater,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
10,
Up,
"-Infinity",
"-Infinity",
Less,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
100,
Floor,
"-Infinity",
"-Infinity",
Less,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
100,
Ceiling,
"-2.0985787164673876924043581168822e323228496",
"-0x7.ffffffffffffffffffffffff8E+268435455#100",
Greater,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
100,
Nearest,
"-Infinity",
"-Infinity",
Less,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
100,
Down,
"-2.0985787164673876924043581168822e323228496",
"-0x7.ffffffffffffffffffffffff8E+268435455#100",
Greater,
);
test(
"-2.0965e323228496",
"-0x7.feE+268435455#10",
100,
Up,
"-Infinity",
"-Infinity",
Less,
);
test(
"744261117.29980",
"0x2c5c85fd.4cc#40",
105,
Floor,
"1.08999377317323357831214151177440e323228496",
"0x4.27b92f7e5b053dc703b866e7b0E+268435455#105",
Less,
);
test(
"744261117.29980",
"0x2c5c85fd.4cc#40",
105,
Ceiling,
"1.08999377317323357831214151177446e323228496",
"0x4.27b92f7e5b053dc703b866e7b4E+268435455#105",
Greater,
);
test(
"744261117.29980",
"0x2c5c85fd.4cc#40",
105,
Nearest,
"1.08999377317323357831214151177446e323228496",
"0x4.27b92f7e5b053dc703b866e7b4E+268435455#105",
Greater,
);
}
#[test]
#[should_panic]
fn sinh_prec_round_fail() {
Float::ONE.sinh_prec_round(0, Nearest);
}
#[test]
#[should_panic]
fn sinh_prec_round_exact_fail() {
Float::ONE.sinh_prec_round(10, Exact);
}
#[test]
#[should_panic]
fn sinh_prec_fail() {
Float::ONE.sinh_prec(0);
}
#[test]
#[should_panic]
fn sinh_round_fail() {
Float::ONE.sinh_round(Exact);
}
#[allow(clippy::needless_pass_by_value)]
fn sinh_prec_round_properties_helper(x: Float, prec: u64, rm: RoundingMode) {
let (c, o) = x.clone().sinh_prec_round(prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.sinh_prec_round_ref(prec, rm);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut x_alt = x.clone();
let o_alt = x_alt.sinh_prec_round_assign(prec, rm);
assert!(x_alt.is_valid());
assert_eq!(ComparableFloatRef(&x_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if let Ok(rug_rm) = rug_round_try_from_rounding_mode(rm) {
let (rug_c, rug_o) = rug_sinh_prec_round(&rug::Float::exact_from(&x), prec, rug_rm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
let (c_neg, o_neg) = (-&x).sinh_prec_round(prec, -rm);
assert_eq!(ComparableFloatRef(&c_neg), ComparableFloatRef(&-&c));
assert_eq!(o_neg, o.reverse());
if !x.is_nan() {
assert!(c.ge_abs(&x) || !c.is_finite() || c.get_prec() < x.get_prec());
assert_eq!(c.is_sign_positive(), x.is_sign_positive());
}
if c.is_normal() {
assert_eq!(c.get_prec(), Some(prec));
}
if o == Equal {
for rm2 in exhaustive_rounding_modes() {
let (c2, o2) = x.sinh_prec_round_ref(prec, rm2);
assert_eq!(ComparableFloat(c2), ComparableFloat(c.clone()));
assert_eq!(o2, Equal);
}
} else {
assert_panic!(x.sinh_prec_round_ref(prec, Exact));
}
}
#[test]
fn sinh_prec_round_properties() {
float_unsigned_rounding_mode_triple_gen_var_36().test_properties(|(x, prec, rm)| {
sinh_prec_round_properties_helper(x, prec, rm);
});
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::NAN.sinh_prec_round(prec, rm);
assert!(c.is_nan());
assert_eq!(o, Equal);
let (c, o) = Float::INFINITY.sinh_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::INFINITY));
assert_eq!(o, Equal);
let (c, o) = Float::NEGATIVE_INFINITY.sinh_prec_round(prec, rm);
assert_eq!(
ComparableFloat(c),
ComparableFloat(Float::NEGATIVE_INFINITY)
);
assert_eq!(o, Equal);
let (c, o) = Float::ZERO.sinh_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::ZERO));
assert_eq!(o, Equal);
let (c, o) = Float::NEGATIVE_ZERO.sinh_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::NEGATIVE_ZERO));
assert_eq!(o, Equal);
});
}
#[test]
fn sinh_round_properties() {
float_rounding_mode_pair_gen_var_47().test_properties(|(x, rm)| {
let (c, o) = x.clone().sinh_round(rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.sinh_round_ref(rm);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut x_alt = x.clone();
let o_alt = x_alt.sinh_round_assign(rm);
assert!(x_alt.is_valid());
assert_eq!(ComparableFloatRef(&x_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = x.sinh_prec_round_ref(x.significant_bits(), rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if let Ok(rug_rm) = rug_round_try_from_rounding_mode(rm) {
let (rug_c, rug_o) = rug_sinh_round(&rug::Float::exact_from(&x), rug_rm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
});
}
#[test]
fn sinh_prec_properties() {
float_unsigned_pair_gen_var_1().test_properties(|(x, prec)| {
let (c, o) = x.clone().sinh_prec(prec);
assert!(c.is_valid());
let (c_alt, o_alt) = x.sinh_prec_ref(prec);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut x_alt = x.clone();
let o_alt = x_alt.sinh_prec_assign(prec);
assert!(x_alt.is_valid());
assert_eq!(ComparableFloatRef(&x_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = x.sinh_prec_round_ref(prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (rug_c, rug_o) = rug_sinh_prec(&rug::Float::exact_from(&x), prec);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
});
}
#[test]
fn sinh_properties() {
float_gen().test_properties(|x| {
let c = x.clone().sinh();
assert!(c.is_valid());
let c_alt = (&x).sinh();
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
let mut x_alt = x.clone();
x_alt.sinh_assign();
assert!(x_alt.is_valid());
assert_eq!(ComparableFloatRef(&x_alt), ComparableFloatRef(&c));
let c_alt = x.sinh_prec_round_ref(x.significant_bits(), Nearest).0;
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(
ComparableFloatRef(&<Float as From<&rug::Float>>::from(&rug_sinh(
&rug::Float::exact_from(&x)
))),
ComparableFloatRef(&c)
);
assert_eq!(ComparableFloatRef(&(-&x).sinh()), ComparableFloatRef(&-&c));
if !x.is_nan() {
assert_eq!(c.is_sign_positive(), x.is_sign_positive());
}
});
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_sinh() {
fn test<T: PrimitiveFloat>(x: T, out: T)
where
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
{
assert_eq!(NiceFloat(primitive_float_sinh(x)), NiceFloat(out));
}
test::<f32>(f32::NAN, f32::NAN);
test::<f32>(f32::INFINITY, f32::INFINITY);
test::<f32>(f32::NEGATIVE_INFINITY, f32::NEGATIVE_INFINITY);
test::<f32>(0.0, 0.0);
test::<f32>(-0.0, -0.0);
test::<f32>(1.0, 1.1752012);
test::<f32>(-1.0, -1.1752012);
test::<f32>(0.5, 0.5210953);
test::<f32>(-0.5, -0.5210953);
test::<f32>(2.0, 3.6268604);
test::<f32>(10.0, 11013.232);
test::<f32>(core::f32::consts::PI, 11.54874);
test::<f32>(88.0, 8.2581813e37);
test::<f32>(89.0, 2.2448064e38);
test::<f32>(89.5, f32::INFINITY);
test::<f32>(-89.5, f32::NEGATIVE_INFINITY);
test::<f32>(90.0, f32::INFINITY);
test::<f32>(1.0e-20, 1.0e-20);
test::<f32>(1.0e-45, 1.0e-45);
test::<f32>(3.4028235e38, f32::INFINITY);
test::<f64>(f64::NAN, f64::NAN);
test::<f64>(f64::INFINITY, f64::INFINITY);
test::<f64>(f64::NEGATIVE_INFINITY, f64::NEGATIVE_INFINITY);
test::<f64>(0.0, 0.0);
test::<f64>(-0.0, -0.0);
test::<f64>(1.0, 1.1752011936438014);
test::<f64>(-1.0, -1.1752011936438014);
test::<f64>(0.5, 0.5210953054937474);
test::<f64>(-0.5, -0.5210953054937474);
test::<f64>(2.0, 3.6268604078470186);
test::<f64>(10.0, 11013.232874703393);
test::<f64>(core::f64::consts::PI, 11.548739357257746);
test::<f64>(709.0, 4.109203730777486e307);
test::<f64>(710.0, 1.1169973830808555e308);
test::<f64>(710.4, 1.6663642832806496e308);
test::<f64>(-710.4, -1.6663642832806496e308);
test::<f64>(711.0, f64::INFINITY);
test::<f64>(1.0e-200, 1.0e-200);
test::<f64>(5.0e-324, 5.0e-324);
test::<f64>(1.7976931348623157e308, f64::INFINITY);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_sinh_properties_helper<T: PrimitiveFloat>()
where
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
{
primitive_float_gen::<T>().test_properties(|x| {
let c = primitive_float_sinh(x);
assert_eq!(c.is_nan(), x.is_nan());
if !x.is_nan() {
assert_eq!(c.is_sign_positive(), x.is_sign_positive());
assert!(c.abs() >= x.abs());
assert_eq!(NiceFloat(primitive_float_sinh(-x)), NiceFloat(-c));
}
if x.is_finite() {
let rug_x = rug::Float::with_val(
u32::exact_from(T::MANTISSA_WIDTH + 1),
&rug::Float::exact_from(&Float::from(x)),
);
let rug_c = <Float as From<&rug::Float>>::from(&rug_x.sinh());
let expected = if rug_c > T::MAX_FINITE {
T::INFINITY
} else if rug_c < -T::MAX_FINITE {
T::NEGATIVE_INFINITY
} else {
T::exact_from(&rug_c)
};
assert_eq!(NiceFloat(expected), NiceFloat(c));
}
});
}
#[test]
fn primitive_float_sinh_properties() {
apply_fn_to_primitive_floats!(primitive_float_sinh_properties_helper);
}
#[test]
fn test_sinh_rational_prec_round() {
let test = |s, prec, rm, out: &str, out_hex: &str, out_o| {
let x = Rational::from_str(s).unwrap();
let (c, o) = Float::sinh_rational_prec_round(x.clone(), prec, rm);
assert!(c.is_valid());
assert_eq!(c.to_string(), out);
assert_eq!(to_hex_string(&c), out_hex);
assert_eq!(o, out_o);
let (c, o) = Float::sinh_rational_prec_round_ref(&x, prec, rm);
assert!(c.is_valid());
assert_eq!(c.to_string(), out);
assert_eq!(to_hex_string(&c), out_hex);
assert_eq!(o, out_o);
if let Ok(rug_rm) = rug_round_try_from_rounding_mode(rm) {
let (rug_c, rug_o) = rug_sinh_rational_prec_round(&x, prec, rug_rm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
};
test("0", 1, Down, "0.0", "0x0.0", Equal);
test("0", 10, Down, "0.0", "0x0.0", Equal);
test("0", 1, Up, "0.0", "0x0.0", Equal);
test("0", 10, Up, "0.0", "0x0.0", Equal);
test("0", 1, Floor, "0.0", "0x0.0", Equal);
test("0", 10, Floor, "0.0", "0x0.0", Equal);
test("0", 1, Ceiling, "0.0", "0x0.0", Equal);
test("0", 10, Ceiling, "0.0", "0x0.0", Equal);
test("0", 1, Nearest, "0.0", "0x0.0", Equal);
test("0", 10, Nearest, "0.0", "0x0.0", Equal);
test("0", 1, Exact, "0.0", "0x0.0", Equal);
test("0", 10, Exact, "0.0", "0x0.0", Equal);
test("3/5", 1, Floor, "0.50", "0x0.8#1", Less);
test("3/5", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("3/5", 1, Nearest, "0.50", "0x0.8#1", Less);
test("3/5", 10, Floor, "0.63574", "0x0.a2c#10", Less);
test("3/5", 10, Ceiling, "0.63672", "0x0.a30#10", Greater);
test("3/5", 10, Nearest, "0.63672", "0x0.a30#10", Greater);
test(
"3/5",
100,
Floor,
"0.63665358214824127112345437546503",
"0x0.a2fbbaaa353beda5841b49fd2#100",
Less,
);
test(
"3/5",
100,
Ceiling,
"0.63665358214824127112345437546582",
"0x0.a2fbbaaa353beda5841b49fd3#100",
Greater,
);
test(
"3/5",
100,
Nearest,
"0.63665358214824127112345437546503",
"0x0.a2fbbaaa353beda5841b49fd2#100",
Less,
);
test("-3/5", 1, Floor, "-1.0", "-0x1.0#1", Less);
test("-3/5", 1, Ceiling, "-0.50", "-0x0.8#1", Greater);
test("-3/5", 1, Nearest, "-0.50", "-0x0.8#1", Greater);
test("-3/5", 10, Floor, "-0.63672", "-0x0.a30#10", Less);
test("-3/5", 10, Ceiling, "-0.63574", "-0x0.a2c#10", Greater);
test("-3/5", 10, Nearest, "-0.63672", "-0x0.a30#10", Less);
test(
"-3/5",
100,
Floor,
"-0.63665358214824127112345437546582",
"-0x0.a2fbbaaa353beda5841b49fd3#100",
Less,
);
test(
"-3/5",
100,
Ceiling,
"-0.63665358214824127112345437546503",
"-0x0.a2fbbaaa353beda5841b49fd2#100",
Greater,
);
test(
"-3/5",
100,
Nearest,
"-0.63665358214824127112345437546503",
"-0x0.a2fbbaaa353beda5841b49fd2#100",
Greater,
);
test("1/3", 1, Floor, "0.25", "0x0.4#1", Less);
test("1/3", 1, Ceiling, "0.50", "0x0.8#1", Greater);
test("1/3", 1, Nearest, "0.25", "0x0.4#1", Less);
test("1/3", 10, Floor, "0.33936", "0x0.56e#10", Less);
test("1/3", 10, Ceiling, "0.33984", "0x0.570#10", Greater);
test("1/3", 10, Nearest, "0.33936", "0x0.56e#10", Less);
test(
"1/3",
100,
Floor,
"0.33954055725615013910126061133846",
"0x0.56ec214514ae05405cea1145d0#100",
Less,
);
test(
"1/3",
100,
Ceiling,
"0.33954055725615013910126061133886",
"0x0.56ec214514ae05405cea1145d8#100",
Greater,
);
test(
"1/3",
100,
Nearest,
"0.33954055725615013910126061133846",
"0x0.56ec214514ae05405cea1145d0#100",
Less,
);
test("22/7", 1, Floor, "8.0", "0x8.0#1", Less);
test("22/7", 1, Ceiling, "16.0", "0x1.0E+1#1", Greater);
test("22/7", 1, Nearest, "8.0", "0x8.0#1", Less);
test("22/7", 10, Floor, "11.562", "0xb.90#10", Less);
test("22/7", 10, Ceiling, "11.578", "0xb.94#10", Greater);
test("22/7", 10, Nearest, "11.562", "0xb.90#10", Less);
test(
"22/7",
100,
Floor,
"11.563406494500513816416460850606",
"0xb.903b68743bd476d7129c12b8#100",
Less,
);
test(
"22/7",
100,
Ceiling,
"11.563406494500513816416460850618",
"0xb.903b68743bd476d7129c12b9#100",
Greater,
);
test(
"22/7",
100,
Nearest,
"11.563406494500513816416460850618",
"0xb.903b68743bd476d7129c12b9#100",
Greater,
);
test("-22/7", 1, Floor, "-16.0", "-0x1.0E+1#1", Less);
test("-22/7", 1, Ceiling, "-8.0", "-0x8.0#1", Greater);
test("-22/7", 1, Nearest, "-8.0", "-0x8.0#1", Greater);
test("-22/7", 10, Floor, "-11.578", "-0xb.94#10", Less);
test("-22/7", 10, Ceiling, "-11.562", "-0xb.90#10", Greater);
test("-22/7", 10, Nearest, "-11.562", "-0xb.90#10", Greater);
test(
"-22/7",
100,
Floor,
"-11.563406494500513816416460850618",
"-0xb.903b68743bd476d7129c12b9#100",
Less,
);
test(
"-22/7",
100,
Ceiling,
"-11.563406494500513816416460850606",
"-0xb.903b68743bd476d7129c12b8#100",
Greater,
);
test(
"-22/7",
100,
Nearest,
"-11.563406494500513816416460850618",
"-0xb.903b68743bd476d7129c12b9#100",
Less,
);
test("100", 1, Floor, "1.1e43", "0x8.0E+35#1", Less);
test("100", 1, Ceiling, "2.2e43", "0x1.0E+36#1", Greater);
test("100", 1, Nearest, "1.1e43", "0x8.0E+35#1", Less);
test("100", 10, Floor, "1.3437e43", "0x9.a4E+35#10", Less);
test("100", 10, Ceiling, "1.3459e43", "0x9.a8E+35#10", Greater);
test("100", 10, Nearest, "1.3437e43", "0x9.a4E+35#10", Less);
test(
"100",
100,
Floor,
"1.3440585709080677242063127757898e43",
"0x9.a4a54d8b8dfa566112849991E+35#100",
Less,
);
test(
"100",
100,
Ceiling,
"1.3440585709080677242063127757915e43",
"0x9.a4a54d8b8dfa566112849992E+35#100",
Greater,
);
test(
"100",
100,
Nearest,
"1.3440585709080677242063127757898e43",
"0x9.a4a54d8b8dfa566112849991E+35#100",
Less,
);
test("-100", 1, Floor, "-2.2e43", "-0x1.0E+36#1", Less);
test("-100", 1, Ceiling, "-1.1e43", "-0x8.0E+35#1", Greater);
test("-100", 1, Nearest, "-1.1e43", "-0x8.0E+35#1", Greater);
test("-100", 10, Floor, "-1.3459e43", "-0x9.a8E+35#10", Less);
test("-100", 10, Ceiling, "-1.3437e43", "-0x9.a4E+35#10", Greater);
test("-100", 10, Nearest, "-1.3437e43", "-0x9.a4E+35#10", Greater);
test(
"-100",
100,
Floor,
"-1.3440585709080677242063127757915e43",
"-0x9.a4a54d8b8dfa566112849992E+35#100",
Less,
);
test(
"-100",
100,
Ceiling,
"-1.3440585709080677242063127757898e43",
"-0x9.a4a54d8b8dfa566112849991E+35#100",
Greater,
);
test(
"-100",
100,
Nearest,
"-1.3440585709080677242063127757898e43",
"-0x9.a4a54d8b8dfa566112849991E+35#100",
Greater,
);
test("1/1000", 1, Floor, "0.00098", "0x0.004#1", Less);
test("1/1000", 1, Ceiling, "0.0020", "0x0.008#1", Greater);
test("1/1000", 1, Nearest, "0.00098", "0x0.004#1", Less);
test("1/1000", 10, Floor, "0.00099945", "0x0.00418#10", Less);
test("1/1000", 10, Ceiling, "0.0010014", "0x0.0041a#10", Greater);
test("1/1000", 10, Nearest, "0.00099945", "0x0.00418#10", Less);
test(
"1/1000",
100,
Floor,
"0.0010000001666666750000001984127008",
"0x0.004189380307278af506711800d0#100",
Less,
);
test(
"1/1000",
100,
Ceiling,
"0.0010000001666666750000001984127023",
"0x0.004189380307278af506711800d8#100",
Greater,
);
test(
"1/1000",
100,
Nearest,
"0.0010000001666666750000001984127008",
"0x0.004189380307278af506711800d0#100",
Less,
);
test("-1/1000000", 1, Floor, "-1.9e-6", "-0x0.00002#1", Less);
test("-1/1000000", 1, Ceiling, "-9.5e-7", "-0x0.00001#1", Greater);
test("-1/1000000", 1, Nearest, "-9.5e-7", "-0x0.00001#1", Greater);
test(
"-1/1000000",
10,
Floor,
"-1.0002e-6",
"-0x0.000010c8#10",
Less,
);
test(
"-1/1000000",
10,
Ceiling,
"-9.9838e-7",
"-0x0.000010c0#10",
Greater,
);
test(
"-1/1000000",
10,
Nearest,
"-1.0002e-6",
"-0x0.000010c8#10",
Less,
);
test(
"-1/1000000",
100,
Floor,
"-1.0000000000001666666666666750015e-6",
"-0x0.000010c6f7a0b5f0a04657c054111a#100",
Less,
);
test(
"-1/1000000",
100,
Ceiling,
"-1.0000000000001666666666666750000e-6",
"-0x0.000010c6f7a0b5f0a04657c0541118#100",
Greater,
);
test(
"-1/1000000",
100,
Nearest,
"-1.0000000000001666666666666750000e-6",
"-0x0.000010c6f7a0b5f0a04657c0541118#100",
Greater,
);
test(
"1/100000000000000000000",
1,
Floor,
"6.8e-21",
"0x2.0E-17#1",
Less,
);
test(
"1/100000000000000000000",
1,
Ceiling,
"1.4e-20",
"0x4.0E-17#1",
Greater,
);
test(
"1/100000000000000000000",
1,
Nearest,
"6.8e-21",
"0x2.0E-17#1",
Less,
);
test(
"1/100000000000000000000",
10,
Floor,
"9.9923e-21",
"0x2.f3E-17#10",
Less,
);
test(
"1/100000000000000000000",
10,
Ceiling,
"1.0006e-20",
"0x2.f4E-17#10",
Greater,
);
test(
"1/100000000000000000000",
10,
Nearest,
"1.0006e-20",
"0x2.f4E-17#10",
Greater,
);
test(
"1/100000000000000000000",
100,
Floor,
"9.9999999999999999999999999999955e-21",
"0x2.f394219248446baa23d2ec728E-17#100",
Less,
);
test(
"1/100000000000000000000",
100,
Ceiling,
"1.0000000000000000000000000000006e-20",
"0x2.f394219248446baa23d2ec72cE-17#100",
Greater,
);
test(
"1/100000000000000000000",
100,
Nearest,
"9.9999999999999999999999999999955e-21",
"0x2.f394219248446baa23d2ec728E-17#100",
Less,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
1,
Floor,
"-3.2e-30",
"-0x4.0E-25#1",
Less,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
1,
Ceiling,
"-1.6e-30",
"-0x2.0E-25#1",
Greater,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
1,
Nearest,
"-3.2e-30",
"-0x4.0E-25#1",
Less,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
10,
Floor,
"-2.3697e-30",
"-0x3.01E-25#10",
Less,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
10,
Ceiling,
"-2.3666e-30",
"-0x3.00E-25#10",
Greater,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
10,
Nearest,
"-2.3666e-30",
"-0x3.00E-25#10",
Greater,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
100,
Floor,
"-2.3665827156630354162351856958508e-30",
"-0x3.0000000000000000000000004E-25#100",
Less,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
100,
Ceiling,
"-2.3665827156630354162351856958484e-30",
"-0x3.0000000000000000000000000E-25#100",
Greater,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
100,
Nearest,
"-2.3665827156630354162351856958484e-30",
"-0x3.0000000000000000000000000E-25#100",
Greater,
);
test(
"1488522235/2",
1,
Floor,
"1.0e323228496",
"0x4.0E+268435455#1",
Less,
);
test("1488522235/2", 1, Ceiling, "Infinity", "Infinity", Greater);
test(
"1488522235/2",
1,
Nearest,
"1.0e323228496",
"0x4.0E+268435455#1",
Less,
);
test(
"1488522235/2",
10,
Floor,
"1.3301e323228496",
"0x5.12E+268435455#10",
Less,
);
test(
"1488522235/2",
10,
Ceiling,
"1.3321e323228496",
"0x5.14E+268435455#10",
Greater,
);
test(
"1488522235/2",
10,
Nearest,
"1.3321e323228496",
"0x5.14E+268435455#10",
Greater,
);
test(
"1488522235/2",
100,
Floor,
"1.3315814500369112065268344141958e323228496",
"0x5.137d0b40cdfb4457d4a570f10E+268435455#100",
Less,
);
test(
"1488522235/2",
100,
Ceiling,
"1.3315814500369112065268344141975e323228496",
"0x5.137d0b40cdfb4457d4a570f18E+268435455#100",
Greater,
);
test(
"1488522235/2",
100,
Nearest,
"1.3315814500369112065268344141975e323228496",
"0x5.137d0b40cdfb4457d4a570f18E+268435455#100",
Greater,
);
test(
"7442611177/10",
1,
Floor,
"1.0e323228496",
"0x4.0E+268435455#1",
Less,
);
test("7442611177/10", 1, Ceiling, "Infinity", "Infinity", Greater);
test("7442611177/10", 1, Nearest, "Infinity", "Infinity", Greater);
test(
"7442611177/10",
10,
Floor,
"1.6252e323228496",
"0x6.32E+268435455#10",
Less,
);
test(
"7442611177/10",
10,
Ceiling,
"1.6272e323228496",
"0x6.34E+268435455#10",
Greater,
);
test(
"7442611177/10",
10,
Nearest,
"1.6272e323228496",
"0x6.34E+268435455#10",
Greater,
);
test(
"7442611177/10",
100,
Floor,
"1.6263972557900017291577754485045e323228496",
"0x6.3332e349c3b727aba6fa728b0E+268435455#100",
Less,
);
test(
"7442611177/10",
100,
Ceiling,
"1.6263972557900017291577754485062e323228496",
"0x6.3332e349c3b727aba6fa728b8E+268435455#100",
Greater,
);
test(
"7442611177/10",
100,
Nearest,
"1.6263972557900017291577754485062e323228496",
"0x6.3332e349c3b727aba6fa728b8E+268435455#100",
Greater,
);
test("-7442611177/10", 1, Floor, "-Infinity", "-Infinity", Less);
test(
"-7442611177/10",
1,
Ceiling,
"-1.0e323228496",
"-0x4.0E+268435455#1",
Greater,
);
test("-7442611177/10", 1, Nearest, "-Infinity", "-Infinity", Less);
test(
"-7442611177/10",
10,
Floor,
"-1.6272e323228496",
"-0x6.34E+268435455#10",
Less,
);
test(
"-7442611177/10",
10,
Ceiling,
"-1.6252e323228496",
"-0x6.32E+268435455#10",
Greater,
);
test(
"-7442611177/10",
10,
Nearest,
"-1.6272e323228496",
"-0x6.34E+268435455#10",
Less,
);
test(
"-7442611177/10",
100,
Floor,
"-1.6263972557900017291577754485062e323228496",
"-0x6.3332e349c3b727aba6fa728b8E+268435455#100",
Less,
);
test(
"-7442611177/10",
100,
Ceiling,
"-1.6263972557900017291577754485045e323228496",
"-0x6.3332e349c3b727aba6fa728b0E+268435455#100",
Greater,
);
test(
"-7442611177/10",
100,
Nearest,
"-1.6263972557900017291577754485062e323228496",
"-0x6.3332e349c3b727aba6fa728b8E+268435455#100",
Less,
);
test(
"744261118",
1,
Floor,
"1.0e323228496",
"0x4.0E+268435455#1",
Less,
);
test("744261118", 1, Ceiling, "Infinity", "Infinity", Greater);
test("744261118", 1, Nearest, "Infinity", "Infinity", Greater);
test(
"744261118",
10,
Floor,
"2.0965e323228496",
"0x7.feE+268435455#10",
Less,
);
test("744261118", 10, Ceiling, "Infinity", "Infinity", Greater);
test("744261118", 10, Nearest, "Infinity", "Infinity", Greater);
test(
"744261118",
100,
Floor,
"2.0985787164673876924043581168822e323228496",
"0x7.ffffffffffffffffffffffff8E+268435455#100",
Less,
);
test("744261118", 100, Ceiling, "Infinity", "Infinity", Greater);
test("744261118", 100, Nearest, "Infinity", "Infinity", Greater);
test("-744261118", 1, Floor, "-Infinity", "-Infinity", Less);
test(
"-744261118",
1,
Ceiling,
"-1.0e323228496",
"-0x4.0E+268435455#1",
Greater,
);
test("-744261118", 1, Nearest, "-Infinity", "-Infinity", Less);
test("-744261118", 10, Floor, "-Infinity", "-Infinity", Less);
test(
"-744261118",
10,
Ceiling,
"-2.0965e323228496",
"-0x7.feE+268435455#10",
Greater,
);
test("-744261118", 10, Nearest, "-Infinity", "-Infinity", Less);
test("-744261118", 100, Floor, "-Infinity", "-Infinity", Less);
test(
"-744261118",
100,
Ceiling,
"-2.0985787164673876924043581168822e323228496",
"-0x7.ffffffffffffffffffffffff8E+268435455#100",
Greater,
);
test("-744261118", 100, Nearest, "-Infinity", "-Infinity", Less);
test(
"10000000000",
1,
Floor,
"1.0e323228496",
"0x4.0E+268435455#1",
Less,
);
test("10000000000", 1, Ceiling, "Infinity", "Infinity", Greater);
test("10000000000", 1, Nearest, "Infinity", "Infinity", Greater);
test(
"10000000000",
10,
Floor,
"2.0965e323228496",
"0x7.feE+268435455#10",
Less,
);
test("10000000000", 10, Ceiling, "Infinity", "Infinity", Greater);
test("10000000000", 10, Nearest, "Infinity", "Infinity", Greater);
test(
"10000000000",
100,
Floor,
"2.0985787164673876924043581168822e323228496",
"0x7.ffffffffffffffffffffffff8E+268435455#100",
Less,
);
test("10000000000", 100, Ceiling, "Infinity", "Infinity", Greater);
test("10000000000", 100, Nearest, "Infinity", "Infinity", Greater);
test(
"1/1000",
100,
Down,
"0.0010000001666666750000001984127008",
"0x0.004189380307278af506711800d0#100",
Less,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
100,
Down,
"-2.3665827156630354162351856958484e-30",
"-0x3.0000000000000000000000000E-25#100",
Greater,
);
test(
"1/1000",
100,
Up,
"0.0010000001666666750000001984127023",
"0x0.004189380307278af506711800d8#100",
Greater,
);
test(
"-108086391056891904/45671926166590716193865151022383844364247891967",
100,
Up,
"-2.3665827156630354162351856958508e-30",
"-0x3.0000000000000000000000004E-25#100",
Less,
);
test("1/65537", 2, Floor, "0.000011", "0x0.0000c#2", Less);
test("1/65537", 2, Ceiling, "0.000015", "0x0.00010#2", Greater);
test("1/65537", 2, Nearest, "0.000015", "0x0.00010#2", Greater);
test("8/4194311", 2, Up, "1.9e-6", "0x0.00002#2", Greater);
test("-8/4194311", 2, Up, "-1.9e-6", "-0x0.00002#2", Less);
}
#[test]
fn test_sinh_rational_extreme() {
let x = Rational::power_of_2(-(1i64 << 30) - 10);
for (rm, out, o_out) in [
(Floor, Float::ZERO, Less),
(Down, Float::ZERO, Less),
(Nearest, Float::ZERO, Less),
(Ceiling, Float::min_positive_value_prec(10), Greater),
(Up, Float::min_positive_value_prec(10), Greater),
] {
let (c, o) = Float::sinh_rational_prec_round_ref(&x, 10, rm);
assert_eq!(ComparableFloat(c.clone()), ComparableFloat(out));
assert_eq!(o, o_out);
let (c_neg, o_neg) = Float::sinh_rational_prec_round(-&x, 10, -rm);
assert_eq!(ComparableFloat(c_neg), ComparableFloat(-c));
assert_eq!(o_neg, o.reverse());
}
let x = Rational::power_of_2(1i64 << 30);
let (c, o) = Float::sinh_rational_prec_round_ref(&x, 10, Nearest);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::INFINITY));
assert_eq!(o, Greater);
let (c, o) = Float::sinh_rational_prec_round(-x, 10, Ceiling);
assert_eq!(
ComparableFloat(c),
ComparableFloat(-Float::max_finite_value_with_prec(10))
);
assert_eq!(o, Greater);
}
#[test]
#[should_panic]
fn sinh_rational_prec_fail() {
Float::sinh_rational_prec(Rational::ONE, 0);
}
#[test]
#[should_panic]
fn sinh_rational_prec_ref_fail() {
Float::sinh_rational_prec_ref(&Rational::ONE, 0);
}
#[test]
#[should_panic]
fn sinh_rational_prec_round_fail_1() {
Float::sinh_rational_prec_round(Rational::ONE, 0, Floor);
}
#[test]
#[should_panic]
fn sinh_rational_prec_round_fail_2() {
Float::sinh_rational_prec_round(Rational::ONE, 10, Exact);
}
#[test]
#[should_panic]
fn sinh_rational_prec_round_ref_fail() {
Float::sinh_rational_prec_round_ref(&Rational::ONE, 10, Exact);
}
#[allow(clippy::needless_pass_by_value)]
fn sinh_rational_prec_round_properties_helper(x: Rational, prec: u64, rm: RoundingMode) {
let (c, o) = Float::sinh_rational_prec_round(x.clone(), prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = Float::sinh_rational_prec_round_ref(&x, prec, rm);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if x != 0u32 {
let (c_neg, o_neg) = Float::sinh_rational_prec_round(-&x, prec, -rm);
assert_eq!(ComparableFloatRef(&c_neg), ComparableFloatRef(&-&c));
assert_eq!(o_neg, o.reverse());
}
if let Ok(rrm) = rug_round_try_from_rounding_mode(rm) {
let (rug_c, rug_o) = rug_sinh_rational_prec_round(&x, prec, rrm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
if c.is_normal() {
assert_eq!(c.get_prec(), Some(prec));
}
if o == Equal {
for rm in exhaustive_rounding_modes() {
let (s, oo) = Float::sinh_rational_prec_round_ref(&x, prec, rm);
assert_eq!(ComparableFloatRef(&s), ComparableFloatRef(&c));
assert_eq!(oo, Equal);
}
} else {
assert_panic!(Float::sinh_rational_prec_round_ref(&x, prec, Exact));
}
}
#[test]
fn sinh_rational_prec_round_properties() {
rational_unsigned_rounding_mode_triple_gen_var_10().test_properties(|(x, prec, rm)| {
sinh_rational_prec_round_properties_helper(x, prec, rm);
});
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::sinh_rational_prec_round(Rational::ZERO, prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::ZERO));
assert_eq!(o, Equal);
});
}
#[allow(clippy::needless_pass_by_value)]
fn sinh_rational_prec_properties_helper(x: Rational, prec: u64) {
let (c, o) = Float::sinh_rational_prec(x.clone(), prec);
assert!(c.is_valid());
let (c_alt, o_alt) = Float::sinh_rational_prec_ref(&x, prec);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = Float::sinh_rational_prec_round_ref(&x, prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (rug_c, rug_o) = rug_sinh_rational_prec(&x, prec);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
if let Ok(f) = Float::try_from(&x) {
let (c_alt, o_alt) = f.sinh_prec(prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
}
}
#[test]
fn sinh_rational_prec_properties() {
rational_unsigned_pair_gen_var_3().test_properties(|(x, prec)| {
sinh_rational_prec_properties_helper(x, prec);
});
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_sinh_rational() {
fn test<T: PrimitiveFloat>(x: &Rational, out: T)
where
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
{
assert_eq!(
NiceFloat(primitive_float_sinh_rational::<T>(x)),
NiceFloat(out)
);
}
let test_s = |s: &str| Rational::from_str(s).unwrap();
test::<f32>(&test_s("0"), 0.0);
test::<f32>(&test_s("1"), 1.1752012);
test::<f32>(&test_s("-1"), -1.1752012);
test::<f32>(&test_s("1/3"), 0.33954057);
test::<f32>(&test_s("-1/3"), -0.33954057);
test::<f32>(&test_s("22/7"), 11.563407);
test::<f32>(&test_s("89"), 2.2448064e38);
test::<f32>(&test_s("90"), f32::INFINITY);
test::<f32>(&test_s("-90"), f32::NEGATIVE_INFINITY);
test::<f32>(&test_s("710"), f32::INFINITY);
test::<f32>(&test_s("7101/10"), f32::INFINITY);
test::<f32>(&test_s("711"), f32::INFINITY);
test::<f32>(&test_s("-711"), f32::NEGATIVE_INFINITY);
test::<f32>(&test_s("10000"), f32::INFINITY);
test::<f32>(&test_s("1/100000000000000000000"), 1.0e-20);
test::<f32>(&test_s("-1/100000000000000000000"), -1.0e-20);
test::<f32>(
&test_s("1/10000000000000000000000000000000000000000"),
1.0e-40,
);
test::<f32>(
&test_s("-1/10000000000000000000000000000000000000000"),
-1.0e-40,
);
test::<f32>(
&test_s("1/100000000000000000000000000000000000000000000000000"),
0.0,
);
test::<f32>(
&test_s("-1/100000000000000000000000000000000000000000000000000"),
-0.0,
);
test::<f64>(&test_s("0"), 0.0);
test::<f64>(&test_s("1"), 1.1752011936438014);
test::<f64>(&test_s("-1"), -1.1752011936438014);
test::<f64>(&test_s("1/3"), 0.3395405572561501);
test::<f64>(&test_s("-1/3"), -0.3395405572561501);
test::<f64>(&test_s("22/7"), 11.563406494500514);
test::<f64>(&test_s("89"), 2.2448064095871728e38);
test::<f64>(&test_s("90"), 6.102016471589204e38);
test::<f64>(&test_s("-90"), -6.102016471589204e38);
test::<f64>(&test_s("710"), 1.1169973830808555e308);
test::<f64>(&test_s("7101/10"), 1.234473023347565e308);
test::<f64>(&test_s("711"), f64::INFINITY);
test::<f64>(&test_s("-711"), f64::NEGATIVE_INFINITY);
test::<f64>(&test_s("10000"), f64::INFINITY);
test::<f64>(&test_s("1/100000000000000000000"), 1.0e-20);
test::<f64>(&test_s("-1/100000000000000000000"), -1.0e-20);
test::<f64>(
&test_s("1/10000000000000000000000000000000000000000"),
1.0e-40,
);
test::<f64>(
&test_s("-1/10000000000000000000000000000000000000000"),
-1.0e-40,
);
test::<f64>(
&test_s("1/100000000000000000000000000000000000000000000000000"),
1.0e-50,
);
test::<f64>(
&test_s("-1/100000000000000000000000000000000000000000000000000"),
-1.0e-50,
);
let x = Rational::power_of_2(-1070i64);
test::<f32>(&x, 0.0);
test::<f64>(&x, 8.0e-323);
test::<f32>(&-&x, -0.0);
test::<f64>(&-x, -8.0e-323);
let x = Rational::from_unsigneds(1u32, 3) >> 1100u32;
test::<f32>(&x, 0.0);
test::<f64>(&x, 0.0);
test::<f32>(&-&x, -0.0);
test::<f64>(&-x, -0.0);
let x = Rational::from_unsigneds(1u32, 3) >> 140u32;
test::<f32>(&x, 2.4e-43);
test::<f64>(&x, 2.3915493791143543e-43);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_sinh_rational_properties_helper<T: PrimitiveFloat>()
where
Float: From<T> + PartialOrd<T>,
Rational: ExactFrom<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
{
rational_gen().test_properties(|x| {
let c = primitive_float_sinh_rational::<T>(&x);
assert!(!c.is_nan());
if x != 0u32 {
assert_eq!(
NiceFloat(primitive_float_sinh_rational::<T>(&-&x)),
NiceFloat(-c)
);
}
let rug_c: T = round_once_to_primitive(|p| {
<Float as From<&rug::Float>>::from(&rug_sinh_rational_prec(&x, p).0)
});
assert_eq!(NiceFloat(rug_c), NiceFloat(c));
});
primitive_float_gen::<T>().test_properties(|x| {
if x.is_finite() && x != T::ZERO {
assert_eq!(
NiceFloat(primitive_float_sinh_rational::<T>(&Rational::exact_from(x))),
NiceFloat(primitive_float_sinh(x))
);
}
});
}
#[test]
fn primitive_float_sinh_rational_properties() {
apply_fn_to_primitive_floats!(primitive_float_sinh_rational_properties_helper);
}