use core::cmp::Ordering::{self, *};
use malachite_base::num::arithmetic::traits::{Cosh, CoshAssign, PowerOf2};
use malachite_base::num::basic::floats::PrimitiveFloat;
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, One, Zero,
};
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::cosh::{
primitive_float_cosh, primitive_float_cosh_rational,
};
use malachite_float::test_util::common::{
assert_rounding_ordering_consistent, parse_hex_string, rug_round_try_from_rounding_mode,
to_hex_string,
};
use malachite_float::test_util::float::arithmetic::cosh::{
rug_cosh, rug_cosh_prec, rug_cosh_prec_round, rug_cosh_rational_prec,
rug_cosh_rational_prec_round, rug_cosh_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_cosh_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().cosh_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.cosh_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.cosh_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_cosh_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, "1.0", "0x1.0#1", Equal);
test("-0.0", "-0x0.0", 1, Nearest, "1.0", "0x1.0#1", Equal);
test("0.0", "0x0.0", 10, Nearest, "1.0000", "0x1.000#10", 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, "2.0", "0x2.0#1", Greater);
test("1.0", "0x1.0#1", 10, Floor, "1.5430", "0x1.8b0#10", Less);
test(
"1.0",
"0x1.0#1",
10,
Ceiling,
"1.5449",
"0x1.8b8#10",
Greater,
);
test("1.0", "0x1.0#1", 10, Nearest, "1.5430", "0x1.8b0#10", Less);
test(
"1.0",
"0x1.0#1",
100,
Floor,
"1.5430806348152437784779056207559",
"0x1.8b07551d9f5504c2bd2810018#100",
Less,
);
test(
"1.0",
"0x1.0#1",
100,
Ceiling,
"1.5430806348152437784779056207575",
"0x1.8b07551d9f5504c2bd281001a#100",
Greater,
);
test(
"1.0",
"0x1.0#1",
100,
Nearest,
"1.5430806348152437784779056207575",
"0x1.8b07551d9f5504c2bd281001a#100",
Greater,
);
test("-1.0", "-0x1.0#1", 10, Floor, "1.5430", "0x1.8b0#10", Less);
test(
"-1.0",
"-0x1.0#1",
10,
Ceiling,
"1.5449",
"0x1.8b8#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
10,
Nearest,
"1.5430",
"0x1.8b0#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
100,
Floor,
"1.5430806348152437784779056207559",
"0x1.8b07551d9f5504c2bd2810018#100",
Less,
);
test(
"-1.0",
"-0x1.0#1",
100,
Ceiling,
"1.5430806348152437784779056207575",
"0x1.8b07551d9f5504c2bd281001a#100",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
100,
Nearest,
"1.5430806348152437784779056207575",
"0x1.8b07551d9f5504c2bd281001a#100",
Greater,
);
test("0.50", "0x0.8#1", 10, Floor, "1.1270", "0x1.208#10", Less);
test(
"0.50",
"0x0.8#1",
10,
Ceiling,
"1.1289",
"0x1.210#10",
Greater,
);
test("0.50", "0x0.8#1", 10, Nearest, "1.1270", "0x1.208#10", Less);
test(
"0.50",
"0x0.8#1",
100,
Floor,
"1.1276259652063807852262251614023",
"0x1.20ac1862ae8d0645823a4f060#100",
Less,
);
test(
"0.50",
"0x0.8#1",
100,
Ceiling,
"1.1276259652063807852262251614039",
"0x1.20ac1862ae8d0645823a4f062#100",
Greater,
);
test(
"0.50",
"0x0.8#1",
100,
Nearest,
"1.1276259652063807852262251614023",
"0x1.20ac1862ae8d0645823a4f060#100",
Less,
);
test("-0.50", "-0x0.8#1", 10, Floor, "1.1270", "0x1.208#10", Less);
test(
"-0.50",
"-0x0.8#1",
10,
Ceiling,
"1.1289",
"0x1.210#10",
Greater,
);
test(
"-0.50",
"-0x0.8#1",
10,
Nearest,
"1.1270",
"0x1.208#10",
Less,
);
test(
"-0.50",
"-0x0.8#1",
100,
Floor,
"1.1276259652063807852262251614023",
"0x1.20ac1862ae8d0645823a4f060#100",
Less,
);
test(
"-0.50",
"-0x0.8#1",
100,
Ceiling,
"1.1276259652063807852262251614039",
"0x1.20ac1862ae8d0645823a4f062#100",
Greater,
);
test(
"-0.50",
"-0x0.8#1",
100,
Nearest,
"1.1276259652063807852262251614023",
"0x1.20ac1862ae8d0645823a4f060#100",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Floor,
"1.0547",
"0x1.0e0#10",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Ceiling,
"1.0566",
"0x1.0e8#10",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Nearest,
"1.0566",
"0x1.0e8#10",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Floor,
"1.0560718678299393895268647082638",
"0x1.0e5ab9d68e232bca22825de22#100",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Ceiling,
"1.0560718678299393895268647082654",
"0x1.0e5ab9d68e232bca22825de24#100",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Nearest,
"1.0560718678299393895268647082638",
"0x1.0e5ab9d68e232bca22825de22#100",
Less,
);
test("2.0", "0x2.0#2", 10, Floor, "3.7617", "0x3.c3#10", Less);
test(
"2.0",
"0x2.0#2",
10,
Ceiling,
"3.7656",
"0x3.c4#10",
Greater,
);
test("2.0", "0x2.0#2", 10, Nearest, "3.7617", "0x3.c3#10", Less);
test(
"2.0",
"0x2.0#2",
100,
Floor,
"3.7621956910836314595622134777725",
"0x3.c31f41be5b3785264fee2eee8#100",
Less,
);
test(
"2.0",
"0x2.0#2",
100,
Ceiling,
"3.7621956910836314595622134777756",
"0x3.c31f41be5b3785264fee2eeec#100",
Greater,
);
test(
"2.0",
"0x2.0#2",
100,
Nearest,
"3.7621956910836314595622134777725",
"0x3.c31f41be5b3785264fee2eee8#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.232920103323139721376090436",
"0x2b05.3ba0a6e25a94579ec1d08c#100",
Less,
);
test(
"10.0",
"0xa.0#4",
100,
Ceiling,
"11013.232920103323139721376090449",
"0x2b05.3ba0a6e25a94579ec1d090#100",
Greater,
);
test(
"10.0",
"0xa.0#4",
100,
Nearest,
"11013.232920103323139721376090436",
"0x2b05.3ba0a6e25a94579ec1d08c#100",
Less,
);
test(
"-100.0",
"-0x64.0#7",
10,
Floor,
"1.3437e43",
"0x9.a4E+35#10",
Less,
);
test(
"-100.0",
"-0x64.0#7",
10,
Ceiling,
"1.3459e43",
"0x9.a8E+35#10",
Greater,
);
test(
"-100.0",
"-0x64.0#7",
10,
Nearest,
"1.3437e43",
"0x9.a4E+35#10",
Less,
);
test(
"-100.0",
"-0x64.0#7",
100,
Floor,
"1.3440585709080677242063127757898e43",
"0x9.a4a54d8b8dfa566112849991E+35#100",
Less,
);
test(
"-100.0",
"-0x64.0#7",
100,
Ceiling,
"1.3440585709080677242063127757915e43",
"0x9.a4a54d8b8dfa566112849992E+35#100",
Greater,
);
test(
"-100.0",
"-0x64.0#7",
100,
Nearest,
"1.3440585709080677242063127757898e43",
"0x9.a4a54d8b8dfa566112849991E+35#100",
Less,
);
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.578",
"0xb.94#10",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Ceiling,
"11.594",
"0xb.98#10",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Nearest,
"11.594",
"0xb.98#10",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Floor,
"11.591953275521520628331101215943",
"0xb.978a3ff720008da5db54fadf#100",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Ceiling,
"11.591953275521520628331101215955",
"0xb.978a3ff720008da5db54fae0#100",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Nearest,
"11.591953275521520628331101215955",
"0xb.978a3ff720008da5db54fae0#100",
Greater,
);
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.7422e43429447",
"0x8.80E+36067375#10",
Less,
);
test(
"100000000.0",
"0x5f5e100.0#27",
10,
Ceiling,
"7.7564e43429447",
"0x8.84E+36067375#10",
Greater,
);
test(
"100000000.0",
"0x5f5e100.0#27",
10,
Nearest,
"7.7564e43429447",
"0x8.84E+36067375#10",
Greater,
);
test(
"100000000.0",
"0x5f5e100.0#27",
100,
Floor,
"7.7498837332421325220922927166673e43429447",
"0x8.8229c7cd3e3c8988ae5d522fE+36067375#100",
Less,
);
test(
"100000000.0",
"0x5f5e100.0#27",
100,
Ceiling,
"7.7498837332421325220922927166788e43429447",
"0x8.8229c7cd3e3c8988ae5d5230E+36067375#100",
Greater,
);
test(
"100000000.0",
"0x5f5e100.0#27",
100,
Nearest,
"7.7498837332421325220922927166673e43429447",
"0x8.8229c7cd3e3c8988ae5d522fE+36067375#100",
Less,
);
test(
"0.00098",
"0x0.004#1",
10,
Floor,
"1.0000",
"0x1.000#10",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Floor,
"1.0000",
"0x1.000#10",
Less,
);
test(
"0.00098",
"0x0.004#1",
10,
Ceiling,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Ceiling,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"0.00098",
"0x0.004#1",
10,
Nearest,
"1.0000",
"0x1.000#10",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Nearest,
"1.0000",
"0x1.000#10",
Less,
);
test(
"0.00098",
"0x0.004#1",
10,
Down,
"1.0000",
"0x1.000#10",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Down,
"1.0000",
"0x1.000#10",
Less,
);
test(
"0.00098",
"0x0.004#1",
10,
Up,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Up,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"0.00098",
"0x0.004#1",
100,
Floor,
"1.0000004768371960987387785411096",
"0x1.00000800000aaaaab05b05b1e#100",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Floor,
"1.0000004768371960987387785411096",
"0x1.00000800000aaaaab05b05b1e#100",
Less,
);
test(
"0.00098",
"0x0.004#1",
100,
Ceiling,
"1.0000004768371960987387785411112",
"0x1.00000800000aaaaab05b05b20#100",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Ceiling,
"1.0000004768371960987387785411112",
"0x1.00000800000aaaaab05b05b20#100",
Greater,
);
test(
"0.00098",
"0x0.004#1",
100,
Nearest,
"1.0000004768371960987387785411112",
"0x1.00000800000aaaaab05b05b20#100",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Nearest,
"1.0000004768371960987387785411112",
"0x1.00000800000aaaaab05b05b20#100",
Greater,
);
test(
"0.00098",
"0x0.004#1",
100,
Down,
"1.0000004768371960987387785411096",
"0x1.00000800000aaaaab05b05b1e#100",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Down,
"1.0000004768371960987387785411096",
"0x1.00000800000aaaaab05b05b1e#100",
Less,
);
test(
"0.00098",
"0x0.004#1",
100,
Up,
"1.0000004768371960987387785411112",
"0x1.00000800000aaaaab05b05b20#100",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Up,
"1.0000004768371960987387785411112",
"0x1.00000800000aaaaab05b05b20#100",
Greater,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Floor,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Less,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Floor,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Less,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Ceiling,
"1.0000000000000000000000000000016",
"0x1.0000000000000000000000002#100",
Greater,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Ceiling,
"1.0000000000000000000000000000016",
"0x1.0000000000000000000000002#100",
Greater,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Nearest,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Less,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Nearest,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Less,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Down,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Less,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Down,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Less,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Up,
"1.0000000000000000000000000000016",
"0x1.0000000000000000000000002#100",
Greater,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Up,
"1.0000000000000000000000000000016",
"0x1.0000000000000000000000002#100",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Floor,
"1.0000",
"0x1.000#10",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Floor,
"1.0000",
"0x1.000#10",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Ceiling,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Ceiling,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Nearest,
"1.0000",
"0x1.000#10",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Nearest,
"1.0000",
"0x1.000#10",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Down,
"1.0000",
"0x1.000#10",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Down,
"1.0000",
"0x1.000#10",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Up,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Up,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Floor,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6890",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000000#300",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Floor,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6890",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000000#300",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Ceiling,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6900",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000002#300",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Ceiling,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6900",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000002#300",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Nearest,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6890",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000000#300",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Nearest,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6890",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000000#300",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Down,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6890",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000000#300",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Down,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6890",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000000#300",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Up,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6900",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000002#300",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Up,
"1.000000000000000000000000000000000000000000000000000000000000311150763893057085357203202\
6900",
"0x1.000000000000000000000000000000000000000000000000008000000000000000000000002#300",
Greater,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Floor,
"1.00000000000000000000",
"0x1.0000000000000000#64",
Less,
);
test(
"1.0e-301030",
"0x1.0E-250000#1",
64,
Floor,
"1.00000000000000000000",
"0x1.0000000000000000#64",
Less,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Ceiling,
"1.00000000000000000011",
"0x1.0000000000000002#64",
Greater,
);
test(
"1.0e-301030",
"0x1.0E-250000#1",
64,
Ceiling,
"1.00000000000000000011",
"0x1.0000000000000002#64",
Greater,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Nearest,
"1.00000000000000000000",
"0x1.0000000000000000#64",
Less,
);
test(
"1.0e-301030",
"0x1.0E-250000#1",
64,
Nearest,
"1.00000000000000000000",
"0x1.0000000000000000#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.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.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(
"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]
#[should_panic]
fn cosh_prec_round_fail() {
Float::ONE.cosh_prec_round(0, Nearest);
}
#[test]
#[should_panic]
fn cosh_prec_round_exact_fail() {
Float::ONE.cosh_prec_round(10, Exact);
}
#[test]
#[should_panic]
fn cosh_prec_fail() {
Float::ONE.cosh_prec(0);
}
#[test]
#[should_panic]
fn cosh_round_fail() {
Float::ONE.cosh_round(Exact);
}
#[allow(clippy::needless_pass_by_value)]
fn cosh_prec_round_properties_helper(x: Float, prec: u64, rm: RoundingMode) {
let (c, o) = x.clone().cosh_prec_round(prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.cosh_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.cosh_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_cosh_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).cosh_prec_round(prec, rm);
assert_eq!(ComparableFloatRef(&c_neg), ComparableFloatRef(&c));
assert_eq!(o_neg, o);
if !x.is_nan() {
assert!(c >= 1u32);
}
if c.is_normal() {
assert_eq!(c.get_prec(), Some(prec));
}
if o == Equal {
for rm2 in exhaustive_rounding_modes() {
let (c2, o2) = x.cosh_prec_round_ref(prec, rm2);
assert_eq!(ComparableFloat(c2), ComparableFloat(c.clone()));
assert_eq!(o2, Equal);
}
} else {
assert_panic!(x.cosh_prec_round_ref(prec, Exact));
}
}
#[test]
fn cosh_prec_round_properties() {
float_unsigned_rounding_mode_triple_gen_var_36().test_properties(|(x, prec, rm)| {
cosh_prec_round_properties_helper(x, prec, rm);
});
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::NAN.cosh_prec_round(prec, rm);
assert!(c.is_nan());
assert_eq!(o, Equal);
let (c, o) = Float::INFINITY.cosh_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::INFINITY));
assert_eq!(o, Equal);
let (c, o) = Float::NEGATIVE_INFINITY.cosh_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::INFINITY));
assert_eq!(o, Equal);
let (c, o) = Float::ZERO.cosh_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::one_prec(prec)));
assert_eq!(o, Equal);
let (c, o) = Float::NEGATIVE_ZERO.cosh_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::one_prec(prec)));
assert_eq!(o, Equal);
});
}
#[test]
fn cosh_round_properties() {
float_rounding_mode_pair_gen_var_47().test_properties(|(x, rm)| {
let (c, o) = x.clone().cosh_round(rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.cosh_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.cosh_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.cosh_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_cosh_round(&rug::Float::exact_from(&x), rug_rm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
});
}
#[test]
fn cosh_prec_properties() {
float_unsigned_pair_gen_var_1().test_properties(|(x, prec)| {
let (c, o) = x.clone().cosh_prec(prec);
assert!(c.is_valid());
let (c_alt, o_alt) = x.cosh_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.cosh_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.cosh_prec_round_ref(prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (rug_c, rug_o) = rug_cosh_prec(&rug::Float::exact_from(&x), prec);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
});
}
#[test]
fn cosh_properties() {
float_gen().test_properties(|x| {
let c = x.clone().cosh();
assert!(c.is_valid());
let c_alt = (&x).cosh();
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
let mut x_alt = x.clone();
x_alt.cosh_assign();
assert!(x_alt.is_valid());
assert_eq!(ComparableFloatRef(&x_alt), ComparableFloatRef(&c));
let c_alt = x.cosh_prec_round_ref(x.significant_bits(), Nearest).0;
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(
ComparableFloatRef(&Float::from(&rug_cosh(&rug::Float::exact_from(&x)))),
ComparableFloatRef(&c)
);
assert_eq!(ComparableFloatRef(&(-&x).cosh()), ComparableFloatRef(&c));
if !x.is_nan() {
assert!(c >= 1u32);
}
});
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_cosh() {
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_cosh(x)), NiceFloat(out));
}
test::<f32>(f32::NAN, f32::NAN);
test::<f32>(f32::INFINITY, f32::INFINITY);
test::<f32>(f32::NEGATIVE_INFINITY, f32::INFINITY);
test::<f32>(0.0, 1.0);
test::<f32>(-0.0, 1.0);
test::<f32>(1.0, 1.5430807);
test::<f32>(-1.0, 1.5430807);
test::<f32>(0.5, 1.127626);
test::<f32>(-0.5, 1.127626);
test::<f32>(2.0, 3.7621956);
test::<f32>(10.0, 11013.233);
test::<f32>(core::f32::consts::PI, 11.591954);
test::<f32>(88.0, 8.2581813e37);
test::<f32>(89.0, 2.2448064e38);
test::<f32>(89.5, f32::INFINITY);
test::<f32>(90.0, f32::INFINITY);
test::<f32>(1.0e-20, 1.0);
test::<f32>(1.0e-45, 1.0);
test::<f32>(3.4028235e38, f32::INFINITY);
test::<f64>(f64::NAN, f64::NAN);
test::<f64>(f64::INFINITY, f64::INFINITY);
test::<f64>(f64::NEGATIVE_INFINITY, f64::INFINITY);
test::<f64>(0.0, 1.0);
test::<f64>(-0.0, 1.0);
test::<f64>(1.0, 1.5430806348152437);
test::<f64>(-1.0, 1.5430806348152437);
test::<f64>(0.5, 1.1276259652063807);
test::<f64>(-0.5, 1.1276259652063807);
test::<f64>(2.0, 3.7621956910836314);
test::<f64>(10.0, 11013.232920103323);
test::<f64>(core::f64::consts::PI, 11.591953275521519);
test::<f64>(709.0, 4.109203730777486e307);
test::<f64>(710.0, 1.1169973830808555e308);
test::<f64>(710.4, 1.6663642832806496e308);
test::<f64>(711.0, f64::INFINITY);
test::<f64>(1.0e-200, 1.0);
test::<f64>(5.0e-324, 1.0);
test::<f64>(1.7976931348623157e308, f64::INFINITY);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_cosh_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_cosh(x);
assert_eq!(c.is_nan(), x.is_nan());
if !x.is_nan() {
assert!(c >= T::ONE);
assert_eq!(NiceFloat(primitive_float_cosh(-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.cosh());
let expected = if rug_c > T::MAX_FINITE {
T::INFINITY
} else {
T::exact_from(&rug_c)
};
assert_eq!(NiceFloat(expected), NiceFloat(c));
}
});
}
#[test]
fn primitive_float_cosh_properties() {
apply_fn_to_primitive_floats!(primitive_float_cosh_properties_helper);
}
#[test]
fn test_cosh_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::cosh_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::cosh_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_cosh_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, "1.0", "0x1.0#1", Equal);
test("0", 10, Down, "1.0000", "0x1.000#10", Equal);
test("0", 1, Up, "1.0", "0x1.0#1", Equal);
test("0", 10, Up, "1.0000", "0x1.000#10", Equal);
test("0", 1, Floor, "1.0", "0x1.0#1", Equal);
test("0", 10, Floor, "1.0000", "0x1.000#10", Equal);
test("0", 1, Ceiling, "1.0", "0x1.0#1", Equal);
test("0", 10, Ceiling, "1.0000", "0x1.000#10", Equal);
test("0", 1, Nearest, "1.0", "0x1.0#1", Equal);
test("0", 10, Nearest, "1.0000", "0x1.000#10", Equal);
test("0", 1, Exact, "1.0", "0x1.0#1", Equal);
test("0", 10, Exact, "1.0000", "0x1.000#10", Equal);
test("3/5", 1, Floor, "1.0", "0x1.0#1", Less);
test("3/5", 1, Ceiling, "2.0", "0x2.0#1", Greater);
test("3/5", 1, Nearest, "1.0", "0x1.0#1", Less);
test("3/5", 10, Floor, "1.1836", "0x1.2f0#10", Less);
test("3/5", 10, Ceiling, "1.1855", "0x1.2f8#10", Greater);
test("3/5", 10, Nearest, "1.1855", "0x1.2f8#10", Greater);
test(
"3/5",
100,
Floor,
"1.1854652182422677037519132926962",
"0x1.2f7aa606e56308c3949cf77fa#100",
Less,
);
test(
"3/5",
100,
Ceiling,
"1.1854652182422677037519132926978",
"0x1.2f7aa606e56308c3949cf77fc#100",
Greater,
);
test(
"3/5",
100,
Nearest,
"1.1854652182422677037519132926978",
"0x1.2f7aa606e56308c3949cf77fc#100",
Greater,
);
test("-3/5", 1, Floor, "1.0", "0x1.0#1", Less);
test("-3/5", 1, Ceiling, "2.0", "0x2.0#1", Greater);
test("-3/5", 1, Nearest, "1.0", "0x1.0#1", Less);
test("-3/5", 10, Floor, "1.1836", "0x1.2f0#10", Less);
test("-3/5", 10, Ceiling, "1.1855", "0x1.2f8#10", Greater);
test("-3/5", 10, Nearest, "1.1855", "0x1.2f8#10", Greater);
test(
"-3/5",
100,
Floor,
"1.1854652182422677037519132926962",
"0x1.2f7aa606e56308c3949cf77fa#100",
Less,
);
test(
"-3/5",
100,
Ceiling,
"1.1854652182422677037519132926978",
"0x1.2f7aa606e56308c3949cf77fc#100",
Greater,
);
test(
"-3/5",
100,
Nearest,
"1.1854652182422677037519132926978",
"0x1.2f7aa606e56308c3949cf77fc#100",
Greater,
);
test("1/3", 1, Floor, "1.0", "0x1.0#1", Less);
test("1/3", 1, Ceiling, "2.0", "0x2.0#1", Greater);
test("1/3", 1, Nearest, "1.0", "0x1.0#1", Less);
test("1/3", 10, Floor, "1.0547", "0x1.0e0#10", Less);
test("1/3", 10, Ceiling, "1.0566", "0x1.0e8#10", Greater);
test("1/3", 10, Nearest, "1.0566", "0x1.0e8#10", Greater);
test(
"1/3",
100,
Floor,
"1.0560718678299393895268647082638",
"0x1.0e5ab9d68e232bca22825de22#100",
Less,
);
test(
"1/3",
100,
Ceiling,
"1.0560718678299393895268647082654",
"0x1.0e5ab9d68e232bca22825de24#100",
Greater,
);
test(
"1/3",
100,
Nearest,
"1.0560718678299393895268647082638",
"0x1.0e5ab9d68e232bca22825de22#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.594", "0xb.98#10", Less);
test("22/7", 10, Ceiling, "11.609", "0xb.9c#10", Greater);
test("22/7", 10, Nearest, "11.609", "0xb.9c#10", Greater);
test(
"22/7",
100,
Floor,
"11.606565803761966414401052945140",
"0xb.9b47e5820793d583f2840c92#100",
Less,
);
test(
"22/7",
100,
Ceiling,
"11.606565803761966414401052945153",
"0xb.9b47e5820793d583f2840c93#100",
Greater,
);
test(
"22/7",
100,
Nearest,
"11.606565803761966414401052945153",
"0xb.9b47e5820793d583f2840c93#100",
Greater,
);
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.594", "0xb.98#10", Less);
test("-22/7", 10, Ceiling, "11.609", "0xb.9c#10", Greater);
test("-22/7", 10, Nearest, "11.609", "0xb.9c#10", Greater);
test(
"-22/7",
100,
Floor,
"11.606565803761966414401052945140",
"0xb.9b47e5820793d583f2840c92#100",
Less,
);
test(
"-22/7",
100,
Ceiling,
"11.606565803761966414401052945153",
"0xb.9b47e5820793d583f2840c93#100",
Greater,
);
test(
"-22/7",
100,
Nearest,
"11.606565803761966414401052945153",
"0xb.9b47e5820793d583f2840c93#100",
Greater,
);
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, "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("1/1000000", 1, Floor, "1.0", "0x1.0#1", Less);
test("1/1000000", 1, Ceiling, "2.0", "0x2.0#1", Greater);
test("1/1000000", 1, Nearest, "1.0", "0x1.0#1", Less);
test("1/1000000", 10, Floor, "1.0000", "0x1.000#10", Less);
test("1/1000000", 10, Ceiling, "1.0020", "0x1.008#10", Greater);
test("1/1000000", 10, Nearest, "1.0000", "0x1.000#10", Less);
test(
"1/1000000",
100,
Floor,
"1.0000000000005000000000000416655",
"0x1.00000000008cbccc096f5d6de#100",
Less,
);
test(
"1/1000000",
100,
Ceiling,
"1.0000000000005000000000000416670",
"0x1.00000000008cbccc096f5d6e0#100",
Greater,
);
test(
"1/1000000",
100,
Nearest,
"1.0000000000005000000000000416670",
"0x1.00000000008cbccc096f5d6e0#100",
Greater,
);
test("-1/1000000", 1, Floor, "1.0", "0x1.0#1", Less);
test("-1/1000000", 1, Ceiling, "2.0", "0x2.0#1", Greater);
test("-1/1000000", 1, Nearest, "1.0", "0x1.0#1", Less);
test("-1/1000000", 10, Floor, "1.0000", "0x1.000#10", Less);
test("-1/1000000", 10, Ceiling, "1.0020", "0x1.008#10", Greater);
test("-1/1000000", 10, Nearest, "1.0000", "0x1.000#10", Less);
test(
"-1/1000000",
100,
Floor,
"1.0000000000005000000000000416655",
"0x1.00000000008cbccc096f5d6de#100",
Less,
);
test(
"-1/1000000",
100,
Ceiling,
"1.0000000000005000000000000416670",
"0x1.00000000008cbccc096f5d6e0#100",
Greater,
);
test(
"-1/1000000",
100,
Nearest,
"1.0000000000005000000000000416670",
"0x1.00000000008cbccc096f5d6e0#100",
Greater,
);
test("1/100000000000000000000", 1, Floor, "1.0", "0x1.0#1", Less);
test(
"1/100000000000000000000",
1,
Ceiling,
"2.0",
"0x2.0#1",
Greater,
);
test(
"1/100000000000000000000",
1,
Nearest,
"1.0",
"0x1.0#1",
Less,
);
test(
"1/100000000000000000000",
10,
Floor,
"1.0000",
"0x1.000#10",
Less,
);
test(
"1/100000000000000000000",
10,
Ceiling,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"1/100000000000000000000",
10,
Nearest,
"1.0000",
"0x1.000#10",
Less,
);
test(
"1/100000000000000000000",
100,
Floor,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Less,
);
test(
"1/100000000000000000000",
100,
Ceiling,
"1.0000000000000000000000000000016",
"0x1.0000000000000000000000002#100",
Greater,
);
test(
"1/100000000000000000000",
100,
Nearest,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Less,
);
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,
"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(
"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(
"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/1180591620717411303424",
10,
Down,
"1.0000",
"0x1.000#10",
Less,
);
test(
"1/1180591620717411303424",
200,
Down,
"1.0000000000000000000000000000000000000000003587324068671531702",
"0x1.00000000000000000000000000000000000800000000000000#200",
Less,
);
test(
"-1/1180591620717411303424",
200,
Down,
"1.0000000000000000000000000000000000000000003587324068671531702",
"0x1.00000000000000000000000000000000000800000000000000#200",
Less,
);
test(
"1/1180591620717411303424",
10,
Up,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"1/1180591620717411303424",
200,
Up,
"1.0000000000000000000000000000000000000000003587324068671531714",
"0x1.00000000000000000000000000000000000800000000000002#200",
Greater,
);
test(
"-1/1180591620717411303424",
200,
Up,
"1.0000000000000000000000000000000000000000003587324068671531714",
"0x1.00000000000000000000000000000000000800000000000002#200",
Greater,
);
test(
"1/1180591620717411303424",
10,
Floor,
"1.0000",
"0x1.000#10",
Less,
);
test(
"1/1180591620717411303424",
200,
Floor,
"1.0000000000000000000000000000000000000000003587324068671531702",
"0x1.00000000000000000000000000000000000800000000000000#200",
Less,
);
test(
"-1/1180591620717411303424",
200,
Floor,
"1.0000000000000000000000000000000000000000003587324068671531702",
"0x1.00000000000000000000000000000000000800000000000000#200",
Less,
);
test(
"1/1180591620717411303424",
10,
Ceiling,
"1.0020",
"0x1.008#10",
Greater,
);
test(
"1/1180591620717411303424",
200,
Ceiling,
"1.0000000000000000000000000000000000000000003587324068671531714",
"0x1.00000000000000000000000000000000000800000000000002#200",
Greater,
);
test(
"-1/1180591620717411303424",
200,
Ceiling,
"1.0000000000000000000000000000000000000000003587324068671531714",
"0x1.00000000000000000000000000000000000800000000000002#200",
Greater,
);
test(
"1/1180591620717411303424",
10,
Nearest,
"1.0000",
"0x1.000#10",
Less,
);
test(
"1/1180591620717411303424",
200,
Nearest,
"1.0000000000000000000000000000000000000000003587324068671531702",
"0x1.00000000000000000000000000000000000800000000000000#200",
Less,
);
test(
"-1/1180591620717411303424",
200,
Nearest,
"1.0000000000000000000000000000000000000000003587324068671531702",
"0x1.00000000000000000000000000000000000800000000000000#200",
Less,
);
}
#[test]
fn test_cosh_rational_extreme() {
let x = Rational::power_of_2(-(1i64 << 30) - 10);
for (rm, out, o_out) in [
(Floor, "1.0000", Less),
(Down, "1.0000", Less),
(Nearest, "1.0000", Less),
(Ceiling, "1.0020", Greater),
(Up, "1.0020", Greater),
] {
let (c, o) = Float::cosh_rational_prec_round_ref(&x, 10, rm);
assert_eq!(c.to_string(), out);
assert_eq!(c.get_prec(), Some(10));
assert_eq!(o, o_out);
let (c_neg, o_neg) = Float::cosh_rational_prec_round(-&x, 10, rm);
assert_eq!(ComparableFloat(c_neg), ComparableFloat(c));
assert_eq!(o_neg, o);
}
let x = Rational::power_of_2(1i64 << 30);
let (c, o) = Float::cosh_rational_prec_round_ref(&x, 10, Nearest);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::INFINITY));
assert_eq!(o, Greater);
let (c, o) = Float::cosh_rational_prec_round(-x, 10, Floor);
assert_eq!(
ComparableFloat(c),
ComparableFloat(Float::max_finite_value_with_prec(10))
);
assert_eq!(o, Less);
}
#[test]
#[should_panic]
fn cosh_rational_prec_fail() {
Float::cosh_rational_prec(Rational::ONE, 0);
}
#[test]
#[should_panic]
fn cosh_rational_prec_ref_fail() {
Float::cosh_rational_prec_ref(&Rational::ONE, 0);
}
#[test]
#[should_panic]
fn cosh_rational_prec_round_fail_1() {
Float::cosh_rational_prec_round(Rational::ONE, 0, Floor);
}
#[test]
#[should_panic]
fn cosh_rational_prec_round_fail_2() {
Float::cosh_rational_prec_round(Rational::ONE, 10, Exact);
}
#[test]
#[should_panic]
fn cosh_rational_prec_round_ref_fail() {
Float::cosh_rational_prec_round_ref(&Rational::ONE, 10, Exact);
}
#[allow(clippy::needless_pass_by_value)]
fn cosh_rational_prec_round_properties_helper(x: Rational, prec: u64, rm: RoundingMode) {
let (c, o) = Float::cosh_rational_prec_round(x.clone(), prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = Float::cosh_rational_prec_round_ref(&x, prec, rm);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
assert!(c >= 1u32);
let (c_neg, o_neg) = Float::cosh_rational_prec_round(-&x, prec, rm);
assert_eq!(ComparableFloatRef(&c_neg), ComparableFloatRef(&c));
assert_eq!(o_neg, o);
if let Ok(rrm) = rug_round_try_from_rounding_mode(rm) {
let (rug_c, rug_o) = rug_cosh_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::cosh_rational_prec_round_ref(&x, prec, rm);
assert_eq!(ComparableFloatRef(&s), ComparableFloatRef(&c));
assert_eq!(oo, Equal);
}
} else {
assert_panic!(Float::cosh_rational_prec_round_ref(&x, prec, Exact));
}
}
#[test]
fn cosh_rational_prec_round_properties() {
rational_unsigned_rounding_mode_triple_gen_var_10().test_properties(|(x, prec, rm)| {
cosh_rational_prec_round_properties_helper(x, prec, rm);
});
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::cosh_rational_prec_round(Rational::ZERO, prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::one_prec(prec)));
assert_eq!(o, Equal);
});
}
#[allow(clippy::needless_pass_by_value)]
fn cosh_rational_prec_properties_helper(x: Rational, prec: u64) {
let (c, o) = Float::cosh_rational_prec(x.clone(), prec);
assert!(c.is_valid());
let (c_alt, o_alt) = Float::cosh_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::cosh_rational_prec_round_ref(&x, prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
assert!(c >= 1u32);
let (rug_c, rug_o) = rug_cosh_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.cosh_prec(prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
}
}
#[test]
fn cosh_rational_prec_properties() {
rational_unsigned_pair_gen_var_3().test_properties(|(x, prec)| {
cosh_rational_prec_properties_helper(x, prec);
});
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_cosh_rational() {
fn test<T: PrimitiveFloat>(s: &str, out: T)
where
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
{
let x = Rational::from_str(s).unwrap();
assert_eq!(
NiceFloat(primitive_float_cosh_rational::<T>(&x)),
NiceFloat(out)
);
}
test::<f32>("0", 1.0);
test::<f32>("1", 1.5430807);
test::<f32>("-1", 1.5430807);
test::<f32>("1/3", 1.0560719);
test::<f32>("-1/3", 1.0560719);
test::<f32>("22/7", 11.606565);
test::<f32>("1/100000000000000000000", 1.0);
test::<f32>("89", 2.2448064e38);
test::<f32>("90", f32::INFINITY);
test::<f32>("710", f32::INFINITY);
test::<f32>("7101/10", f32::INFINITY);
test::<f32>("711", f32::INFINITY);
test::<f32>("10000", f32::INFINITY);
test::<f64>("0", 1.0);
test::<f64>("1", 1.5430806348152437);
test::<f64>("-1", 1.5430806348152437);
test::<f64>("1/3", 1.0560718678299394);
test::<f64>("-1/3", 1.0560718678299394);
test::<f64>("22/7", 11.606565803761967);
test::<f64>("1/100000000000000000000", 1.0);
test::<f64>("89", 2.2448064095871728e38);
test::<f64>("90", 6.102016471589204e38);
test::<f64>("710", 1.1169973830808555e308);
test::<f64>("7101/10", 1.234473023347565e308);
test::<f64>("711", f64::INFINITY);
test::<f64>("10000", f64::INFINITY);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_cosh_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_cosh_rational::<T>(&x);
assert!(c >= T::ONE);
assert_eq!(
NiceFloat(primitive_float_cosh_rational::<T>(&-&x)),
NiceFloat(c)
);
let rug_c = <Float as From<&rug::Float>>::from(
&rug_cosh_rational_prec(&x, T::MANTISSA_WIDTH + 1).0,
);
let expected = if rug_c > T::MAX_FINITE {
T::INFINITY
} else {
T::exact_from(&rug_c)
};
assert_eq!(NiceFloat(expected), NiceFloat(c));
});
primitive_float_gen::<T>().test_properties(|x| {
if x.is_finite() {
assert_eq!(
NiceFloat(primitive_float_cosh_rational::<T>(&Rational::exact_from(x))),
NiceFloat(primitive_float_cosh(x))
);
}
});
}
#[test]
fn primitive_float_cosh_rational_properties() {
apply_fn_to_primitive_floats!(primitive_float_cosh_rational_properties_helper);
}