use core::cmp::Ordering::{self, *};
use malachite_base::num::arithmetic::traits::{PowerOf2, Sech, SechAssign};
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::sech::{
primitive_float_sech, primitive_float_sech_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::sech::{
rug_sech, rug_sech_prec, rug_sech_prec_round, rug_sech_rational_prec,
rug_sech_rational_prec_round, rug_sech_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_sech_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().sech_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.sech_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.sech_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_sech_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, "0.0", "0x0.0", Equal);
test("-Infinity", "-Infinity", 1, Nearest, "0.0", "0x0.0", 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, "0.50", "0x0.8#1", Less);
test("1.0", "0x1.0#1", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("1.0", "0x1.0#1", 1, Nearest, "0.50", "0x0.8#1", Less);
test("1.0", "0x1.0#1", 10, Floor, "0.64746", "0x0.a5c#10", Less);
test(
"1.0",
"0x1.0#1",
10,
Ceiling,
"0.64844",
"0x0.a60#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
10,
Nearest,
"0.64844",
"0x0.a60#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
100,
Floor,
"0.64805427366388539957497735322564",
"0x0.a5e6e2876b5f3b99e515f5ceb#100",
Less,
);
test(
"1.0",
"0x1.0#1",
100,
Ceiling,
"0.64805427366388539957497735322643",
"0x0.a5e6e2876b5f3b99e515f5cec#100",
Greater,
);
test(
"1.0",
"0x1.0#1",
100,
Nearest,
"0.64805427366388539957497735322643",
"0x0.a5e6e2876b5f3b99e515f5cec#100",
Greater,
);
test("-1.0", "-0x1.0#1", 10, Floor, "0.64746", "0x0.a5c#10", Less);
test(
"-1.0",
"-0x1.0#1",
10,
Ceiling,
"0.64844",
"0x0.a60#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
10,
Nearest,
"0.64844",
"0x0.a60#10",
Greater,
);
test("-1.0", "-0x1.0#1", 10, Down, "0.64746", "0x0.a5c#10", Less);
test("-1.0", "-0x1.0#1", 10, Up, "0.64844", "0x0.a60#10", Greater);
test(
"-1.0",
"-0x1.0#1",
100,
Floor,
"0.64805427366388539957497735322564",
"0x0.a5e6e2876b5f3b99e515f5ceb#100",
Less,
);
test(
"-1.0",
"-0x1.0#1",
100,
Ceiling,
"0.64805427366388539957497735322643",
"0x0.a5e6e2876b5f3b99e515f5cec#100",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
100,
Nearest,
"0.64805427366388539957497735322643",
"0x0.a5e6e2876b5f3b99e515f5cec#100",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
100,
Down,
"0.64805427366388539957497735322564",
"0x0.a5e6e2876b5f3b99e515f5ceb#100",
Less,
);
test(
"-1.0",
"-0x1.0#1",
100,
Up,
"0.64805427366388539957497735322643",
"0x0.a5e6e2876b5f3b99e515f5cec#100",
Greater,
);
test("0.50", "0x0.8#1", 10, Floor, "0.88672", "0x0.e30#10", Less);
test(
"0.50",
"0x0.8#1",
10,
Ceiling,
"0.88770",
"0x0.e34#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
10,
Nearest,
"0.88672",
"0x0.e30#10",
Less,
);
test("0.50", "0x0.8#1", 10, Down, "0.88672", "0x0.e30#10", Less);
test("0.50", "0x0.8#1", 10, Up, "0.88770", "0x0.e34#10", Greater);
test(
"0.50",
"0x0.8#1",
100,
Floor,
"0.88681888397007390865889779778288",
"0x0.e3068ff8206e7fbc254fca8dd#100",
Less,
);
test(
"0.50",
"0x0.8#1",
100,
Ceiling,
"0.88681888397007390865889779778367",
"0x0.e3068ff8206e7fbc254fca8de#100",
Greater,
);
test(
"0.50",
"0x0.8#1",
100,
Nearest,
"0.88681888397007390865889779778367",
"0x0.e3068ff8206e7fbc254fca8de#100",
Greater,
);
test(
"0.50",
"0x0.8#1",
100,
Down,
"0.88681888397007390865889779778288",
"0x0.e3068ff8206e7fbc254fca8dd#100",
Less,
);
test(
"0.50",
"0x0.8#1",
100,
Up,
"0.88681888397007390865889779778367",
"0x0.e3068ff8206e7fbc254fca8de#100",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Floor,
"0.94629",
"0x0.f24#10",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Ceiling,
"0.94727",
"0x0.f28#10",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Nearest,
"0.94727",
"0x0.f28#10",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Down,
"0.94629",
"0x0.f24#10",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
10,
Up,
"0.94727",
"0x0.f28#10",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Floor,
"0.94690525376349792655895228013934",
"0x0.f26861f95326637981841f9c9#100",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Ceiling,
"0.94690525376349792655895228014013",
"0x0.f26861f95326637981841f9ca#100",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Nearest,
"0.94690525376349792655895228014013",
"0x0.f26861f95326637981841f9ca#100",
Greater,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Down,
"0.94690525376349792655895228013934",
"0x0.f26861f95326637981841f9c9#100",
Less,
);
test(
"0.33333333333333333333333333333346",
"0x0.55555555555555555555555558#100",
100,
Up,
"0.94690525376349792655895228014013",
"0x0.f26861f95326637981841f9ca#100",
Greater,
);
test("2.0", "0x2.0#2", 10, Floor, "0.26562", "0x0.440#10", Less);
test(
"2.0",
"0x2.0#2",
10,
Ceiling,
"0.26611",
"0x0.442#10",
Greater,
);
test("2.0", "0x2.0#2", 10, Nearest, "0.26562", "0x0.440#10", Less);
test("2.0", "0x2.0#2", 10, Down, "0.26562", "0x0.440#10", Less);
test("2.0", "0x2.0#2", 10, Up, "0.26611", "0x0.442#10", Greater);
test(
"2.0",
"0x2.0#2",
100,
Floor,
"0.26580222883407969212086273981965",
"0x0.440b9d680bd909be0bba5faa30#100",
Less,
);
test(
"2.0",
"0x2.0#2",
100,
Ceiling,
"0.26580222883407969212086273982004",
"0x0.440b9d680bd909be0bba5faa38#100",
Greater,
);
test(
"2.0",
"0x2.0#2",
100,
Nearest,
"0.26580222883407969212086273982004",
"0x0.440b9d680bd909be0bba5faa38#100",
Greater,
);
test(
"2.0",
"0x2.0#2",
100,
Down,
"0.26580222883407969212086273981965",
"0x0.440b9d680bd909be0bba5faa30#100",
Less,
);
test(
"2.0",
"0x2.0#2",
100,
Up,
"0.26580222883407969212086273982004",
"0x0.440b9d680bd909be0bba5faa38#100",
Greater,
);
test(
"-10.0",
"-0xa.0#4",
10,
Floor,
"0.000090718",
"0x0.0005f2#10",
Less,
);
test(
"-10.0",
"-0xa.0#4",
10,
Ceiling,
"0.000090837",
"0x0.0005f4#10",
Greater,
);
test(
"-10.0",
"-0xa.0#4",
10,
Nearest,
"0.000090837",
"0x0.0005f4#10",
Greater,
);
test(
"-10.0",
"-0xa.0#4",
10,
Down,
"0.000090718",
"0x0.0005f2#10",
Less,
);
test(
"-10.0",
"-0xa.0#4",
10,
Up,
"0.000090837",
"0x0.0005f4#10",
Greater,
);
test(
"-10.0",
"-0xa.0#4",
100,
Floor,
"0.000090799859337817244080129507820451",
"0x0.0005f35e6d24716523902208e1c68#100",
Less,
);
test(
"-10.0",
"-0xa.0#4",
100,
Ceiling,
"0.000090799859337817244080129507820547",
"0x0.0005f35e6d24716523902208e1c70#100",
Greater,
);
test(
"-10.0",
"-0xa.0#4",
100,
Nearest,
"0.000090799859337817244080129507820451",
"0x0.0005f35e6d24716523902208e1c68#100",
Less,
);
test(
"-10.0",
"-0xa.0#4",
100,
Down,
"0.000090799859337817244080129507820451",
"0x0.0005f35e6d24716523902208e1c68#100",
Less,
);
test(
"-10.0",
"-0xa.0#4",
100,
Up,
"0.000090799859337817244080129507820547",
"0x0.0005f35e6d24716523902208e1c70#100",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Floor,
"0.086182",
"0x0.1610#10",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Ceiling,
"0.086304",
"0x0.1618#10",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Nearest,
"0.086304",
"0x0.1618#10",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Down,
"0.086182",
"0x0.1610#10",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
10,
Up,
"0.086304",
"0x0.1618#10",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Floor,
"0.086266738334054414692242558742055",
"0x0.161593b3e09a38b7e026782e56#100",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Ceiling,
"0.086266738334054414692242558742154",
"0x0.161593b3e09a38b7e026782e58#100",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Nearest,
"0.086266738334054414692242558742055",
"0x0.161593b3e09a38b7e026782e56#100",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Down,
"0.086266738334054414692242558742055",
"0x0.161593b3e09a38b7e026782e56#100",
Less,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
100,
Up,
"0.086266738334054414692242558742154",
"0x0.161593b3e09a38b7e026782e58#100",
Greater,
);
test(
"1000.0",
"0x3e8.0#10",
10,
Floor,
"1.0144e-434",
"0x4.f0E-361#10",
Less,
);
test(
"1000.0",
"0x3e8.0#10",
10,
Ceiling,
"1.0160e-434",
"0x4.f2E-361#10",
Greater,
);
test(
"1000.0",
"0x3e8.0#10",
10,
Nearest,
"1.0160e-434",
"0x4.f2E-361#10",
Greater,
);
test(
"1000.0",
"0x3e8.0#10",
10,
Down,
"1.0144e-434",
"0x4.f0E-361#10",
Less,
);
test(
"1000.0",
"0x3e8.0#10",
10,
Up,
"1.0160e-434",
"0x4.f2E-361#10",
Greater,
);
test(
"1000.0",
"0x3e8.0#10",
100,
Floor,
"1.0151917795098913530583618959146e-434",
"0x4.f1086790625503cc93d1b9e50E-361#100",
Less,
);
test(
"1000.0",
"0x3e8.0#10",
100,
Ceiling,
"1.0151917795098913530583618959159e-434",
"0x4.f1086790625503cc93d1b9e58E-361#100",
Greater,
);
test(
"1000.0",
"0x3e8.0#10",
100,
Nearest,
"1.0151917795098913530583618959146e-434",
"0x4.f1086790625503cc93d1b9e50E-361#100",
Less,
);
test(
"1000.0",
"0x3e8.0#10",
100,
Down,
"1.0151917795098913530583618959146e-434",
"0x4.f1086790625503cc93d1b9e50E-361#100",
Less,
);
test(
"1000.0",
"0x3e8.0#10",
100,
Up,
"1.0151917795098913530583618959159e-434",
"0x4.f1086790625503cc93d1b9e58E-361#100",
Greater,
);
test(
"1000000.0",
"0xf4240.0#20",
10,
Floor,
"6.5911e-434295",
"0x3.e3E-360674#10",
Less,
);
test(
"1000000.0",
"0xf4240.0#20",
10,
Ceiling,
"6.5977e-434295",
"0x3.e4E-360674#10",
Greater,
);
test(
"1000000.0",
"0xf4240.0#20",
10,
Nearest,
"6.5911e-434295",
"0x3.e3E-360674#10",
Less,
);
test(
"1000000.0",
"0xf4240.0#20",
10,
Down,
"6.5911e-434295",
"0x3.e3E-360674#10",
Less,
);
test(
"1000000.0",
"0xf4240.0#20",
10,
Up,
"6.5977e-434295",
"0x3.e4E-360674#10",
Greater,
);
test(
"1000000.0",
"0xf4240.0#20",
100,
Floor,
"6.5936629561771171579378159382151e-434295",
"0x3.e362986bdaa297eea886313f4E-360674#100",
Less,
);
test(
"1000000.0",
"0xf4240.0#20",
100,
Ceiling,
"6.5936629561771171579378159382204e-434295",
"0x3.e362986bdaa297eea886313f8E-360674#100",
Greater,
);
test(
"1000000.0",
"0xf4240.0#20",
100,
Nearest,
"6.5936629561771171579378159382151e-434295",
"0x3.e362986bdaa297eea886313f4E-360674#100",
Less,
);
test(
"1000000.0",
"0xf4240.0#20",
100,
Down,
"6.5936629561771171579378159382151e-434295",
"0x3.e362986bdaa297eea886313f4E-360674#100",
Less,
);
test(
"1000000.0",
"0xf4240.0#20",
100,
Up,
"6.5936629561771171579378159382204e-434295",
"0x3.e362986bdaa297eea886313f8E-360674#100",
Greater,
);
test(
"5.4e8",
"0x2.0E+7#1",
10,
Floor,
"5.3094e-233160075",
"0x6.52E-193635251#10",
Less,
);
test(
"5.4e8",
"0x2.0E+7#1",
10,
Ceiling,
"5.3159e-233160075",
"0x6.54E-193635251#10",
Greater,
);
test(
"5.4e8",
"0x2.0E+7#1",
10,
Nearest,
"5.3094e-233160075",
"0x6.52E-193635251#10",
Less,
);
test(
"5.4e8",
"0x2.0E+7#1",
10,
Down,
"5.3094e-233160075",
"0x6.52E-193635251#10",
Less,
);
test(
"5.4e8",
"0x2.0E+7#1",
10,
Up,
"5.3159e-233160075",
"0x6.54E-193635251#10",
Greater,
);
test(
"5.4e8",
"0x2.0E+7#1",
100,
Floor,
"5.3096230646839805874289616336017e-233160075",
"0x6.5213d1f51096f677b1bdae508E-193635251#100",
Less,
);
test(
"5.4e8",
"0x2.0E+7#1",
100,
Ceiling,
"5.3096230646839805874289616336070e-233160075",
"0x6.5213d1f51096f677b1bdae510E-193635251#100",
Greater,
);
test(
"5.4e8",
"0x2.0E+7#1",
100,
Nearest,
"5.3096230646839805874289616336070e-233160075",
"0x6.5213d1f51096f677b1bdae510E-193635251#100",
Greater,
);
test(
"5.4e8",
"0x2.0E+7#1",
100,
Down,
"5.3096230646839805874289616336017e-233160075",
"0x6.5213d1f51096f677b1bdae508E-193635251#100",
Less,
);
test(
"5.4e8",
"0x2.0E+7#1",
100,
Up,
"5.3096230646839805874289616336070e-233160075",
"0x6.5213d1f51096f677b1bdae510E-193635251#100",
Greater,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Floor,
"9.3025e-304006138",
"0x1.4c8E-252471632#10",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Ceiling,
"9.3165e-304006138",
"0x1.4d0E-252471632#10",
Greater,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Nearest,
"9.3025e-304006138",
"0x1.4c8E-252471632#10",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Down,
"9.3025e-304006138",
"0x1.4c8E-252471632#10",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
10,
Up,
"9.3165e-304006138",
"0x1.4d0E-252471632#10",
Greater,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Floor,
"9.3058000397652234489131203297804e-304006138",
"0x1.4c9e6550bdb38bcdec64deb32E-252471632#100",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Ceiling,
"9.3058000397652234489131203297917e-304006138",
"0x1.4c9e6550bdb38bcdec64deb34E-252471632#100",
Greater,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Nearest,
"9.3058000397652234489131203297917e-304006138",
"0x1.4c9e6550bdb38bcdec64deb34E-252471632#100",
Greater,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Down,
"9.3058000397652234489131203297804e-304006138",
"0x1.4c9e6550bdb38bcdec64deb32E-252471632#100",
Less,
);
test(
"700000000.00",
"0x29b92700.0#30",
100,
Up,
"9.3058000397652234489131203297917e-304006138",
"0x1.4c9e6550bdb38bcdec64deb34E-252471632#100",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Floor,
"7.5014e-323228497",
"0x3.26E-268435456#10",
Less,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Ceiling,
"7.5107e-323228497",
"0x3.27E-268435456#10",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Nearest,
"7.5107e-323228497",
"0x3.27E-268435456#10",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Down,
"7.5014e-323228497",
"0x3.26E-268435456#10",
Less,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
10,
Up,
"7.5107e-323228497",
"0x3.27E-268435456#10",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Floor,
"7.5098673083218467310380527281516e-323228497",
"0x3.26ea18e02da8f8a2632086ef8E-268435456#100",
Less,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Ceiling,
"7.5098673083218467310380527281592e-323228497",
"0x3.26ea18e02da8f8a2632086efcE-268435456#100",
Greater,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Nearest,
"7.5098673083218467310380527281516e-323228497",
"0x3.26ea18e02da8f8a2632086ef8E-268435456#100",
Less,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Down,
"7.5098673083218467310380527281516e-323228497",
"0x3.26ea18e02da8f8a2632086ef8E-268435456#100",
Less,
);
test(
"744261117.50",
"0x2c5c85fd.8#31",
100,
Up,
"7.5098673083218467310380527281592e-323228497",
"0x3.26ea18e02da8f8a2632086efcE-268435456#100",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Floor,
"7.5014e-323228497",
"0x3.26E-268435456#10",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Ceiling,
"7.5107e-323228497",
"0x3.27E-268435456#10",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Nearest,
"7.5107e-323228497",
"0x3.27E-268435456#10",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Down,
"7.5014e-323228497",
"0x3.26E-268435456#10",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
10,
Up,
"7.5107e-323228497",
"0x3.27E-268435456#10",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Floor,
"7.5098673083218467310380527281516e-323228497",
"0x3.26ea18e02da8f8a2632086ef8E-268435456#100",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Ceiling,
"7.5098673083218467310380527281592e-323228497",
"0x3.26ea18e02da8f8a2632086efcE-268435456#100",
Greater,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Nearest,
"7.5098673083218467310380527281516e-323228497",
"0x3.26ea18e02da8f8a2632086ef8E-268435456#100",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Down,
"7.5098673083218467310380527281516e-323228497",
"0x3.26ea18e02da8f8a2632086ef8E-268435456#100",
Less,
);
test(
"-744261117.50",
"-0x2c5c85fd.8#31",
100,
Up,
"7.5098673083218467310380527281592e-323228497",
"0x3.26ea18e02da8f8a2632086efcE-268435456#100",
Greater,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
10,
Floor,
"2.7595e-323228497",
"0x1.288E-268435456#10",
Less,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
10,
Ceiling,
"2.7641e-323228497",
"0x1.290E-268435456#10",
Greater,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
10,
Nearest,
"2.7641e-323228497",
"0x1.290E-268435456#10",
Greater,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
10,
Down,
"2.7595e-323228497",
"0x1.288E-268435456#10",
Less,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
10,
Up,
"2.7641e-323228497",
"0x1.290E-268435456#10",
Greater,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
100,
Floor,
"2.7627257886571247097149806987996e-323228497",
"0x1.28d8e45434c7216121ffbfc56E-268435456#100",
Less,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
100,
Ceiling,
"2.7627257886571247097149806988033e-323228497",
"0x1.28d8e45434c7216121ffbfc58E-268435456#100",
Greater,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
100,
Nearest,
"2.7627257886571247097149806988033e-323228497",
"0x1.28d8e45434c7216121ffbfc58E-268435456#100",
Greater,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
100,
Down,
"2.7627257886571247097149806987996e-323228497",
"0x1.28d8e45434c7216121ffbfc56E-268435456#100",
Less,
);
test(
"744261118.50",
"0x2c5c85fe.8#31",
100,
Up,
"2.7627257886571247097149806988033e-323228497",
"0x1.28d8e45434c7216121ffbfc58E-268435456#100",
Greater,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
10,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
10,
Nearest,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
10,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
10,
Up,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
100,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
100,
Nearest,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
100,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.00000",
"0x2c5c85ff.000#40",
100,
Up,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
10,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
10,
Nearest,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
10,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
10,
Up,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
100,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
100,
Nearest,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
100,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.29980",
"0x2c5c85ff.4cc#40",
100,
Up,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
10,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
10,
Nearest,
"0.0",
"0x0.0",
Less,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
10,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
10,
Up,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
100,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
100,
Nearest,
"0.0",
"0x0.0",
Less,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
100,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"-744261119.59961",
"-0x2c5c85ff.998#40",
100,
Up,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
10,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
10,
Nearest,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
10,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
10,
Up,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
100,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
100,
Nearest,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
100,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"744261119.90039",
"0x2c5c85ff.e68#40",
100,
Up,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
10,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
10,
Nearest,
"0.0",
"0x0.0",
Less,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
10,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
10,
Up,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
100,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
100,
Nearest,
"0.0",
"0x0.0",
Less,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
100,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"744261120.00",
"0x2c5c8600.0#30",
100,
Up,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Nearest,
"0.0",
"0x0.0",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
10,
Up,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Floor,
"0.0",
"0x0.0",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Nearest,
"0.0",
"0x0.0",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Down,
"0.0",
"0x0.0",
Less,
);
test(
"2.0965e323228496",
"0x7.feE+268435455#10",
100,
Up,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"0.00098",
"0x0.004#1",
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.00098",
"0x0.004#1",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.00098",
"0x0.004#1",
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.00098",
"0x0.004#1",
10,
Down,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Down,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.00098",
"0x0.004#1",
10,
Up,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
10,
Up,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.00098",
"0x0.004#1",
100,
Floor,
"0.99999952316303127486438457454987",
"0x0.fffff80000355553fa4fadc57#100",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Floor,
"0.99999952316303127486438457454987",
"0x0.fffff80000355553fa4fadc57#100",
Less,
);
test(
"0.00098",
"0x0.004#1",
100,
Ceiling,
"0.99999952316303127486438457455066",
"0x0.fffff80000355553fa4fadc58#100",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Ceiling,
"0.99999952316303127486438457455066",
"0x0.fffff80000355553fa4fadc58#100",
Greater,
);
test(
"0.00098",
"0x0.004#1",
100,
Nearest,
"0.99999952316303127486438457455066",
"0x0.fffff80000355553fa4fadc58#100",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Nearest,
"0.99999952316303127486438457455066",
"0x0.fffff80000355553fa4fadc58#100",
Greater,
);
test(
"0.00098",
"0x0.004#1",
100,
Down,
"0.99999952316303127486438457454987",
"0x0.fffff80000355553fa4fadc57#100",
Less,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Down,
"0.99999952316303127486438457454987",
"0x0.fffff80000355553fa4fadc57#100",
Less,
);
test(
"0.00098",
"0x0.004#1",
100,
Up,
"0.99999952316303127486438457455066",
"0x0.fffff80000355553fa4fadc58#100",
Greater,
);
test(
"-0.00098",
"-0x0.004#1",
100,
Up,
"0.99999952316303127486438457455066",
"0x0.fffff80000355553fa4fadc58#100",
Greater,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Floor,
"0.99999999999999999999999999999921",
"0x0.fffffffffffffffffffffffff#100",
Less,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Floor,
"0.99999999999999999999999999999921",
"0x0.fffffffffffffffffffffffff#100",
Less,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Ceiling,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Ceiling,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Nearest,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Nearest,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Down,
"0.99999999999999999999999999999921",
"0x0.fffffffffffffffffffffffff#100",
Less,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Down,
"0.99999999999999999999999999999921",
"0x0.fffffffffffffffffffffffff#100",
Less,
);
test(
"8.9e-16",
"0x4.0E-13#1",
100,
Up,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"-8.9e-16",
"-0x4.0E-13#1",
100,
Up,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Down,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Down,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
10,
Up,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
10,
Up,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Floor,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31099",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000#300",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Floor,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31099",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000#300",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Ceiling,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31148",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000001#300",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Ceiling,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31148",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000001#300",
Greater,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Nearest,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31099",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000#300",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Nearest,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31099",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000#300",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Down,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31099",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000#300",
Less,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Down,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31099",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000#300",
Less,
);
test(
"7.9e-31",
"0x1.0E-25#1",
300,
Up,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31148",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000001#300",
Greater,
);
test(
"-7.9e-31",
"-0x1.0E-25#1",
300,
Up,
"0.999999999999999999999999999999999999999999999999999999999999688849236106942914642796797\
31148",
"0x0.ffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000001#300",
Greater,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Floor,
"0.999999999999999999946",
"0x0.ffffffffffffffff#64",
Less,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Ceiling,
"1.00000000000000000000",
"0x1.0000000000000000#64",
Greater,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Nearest,
"1.00000000000000000000",
"0x1.0000000000000000#64",
Greater,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Down,
"0.999999999999999999946",
"0x0.ffffffffffffffff#64",
Less,
);
test(
"2.4e-323228497",
"0x1.0E-268435456#1",
64,
Up,
"1.00000000000000000000",
"0x1.0000000000000000#64",
Greater,
);
test(
"623740651.00",
"0x252d86eb.0#30",
1,
Floor,
"2.7e-270887123",
"0x2.0E-224966886#1",
Less,
);
test(
"623740651.00",
"0x252d86eb.0#30",
1,
Ceiling,
"5.4e-270887123",
"0x4.0E-224966886#1",
Greater,
);
test(
"623740651.00",
"0x252d86eb.0#30",
1,
Nearest,
"2.7e-270887123",
"0x2.0E-224966886#1",
Less,
);
}
#[test]
#[should_panic]
fn sech_prec_round_fail() {
Float::ONE.sech_prec_round(0, Nearest);
}
#[test]
#[should_panic]
fn sech_prec_round_exact_fail() {
Float::ONE.sech_prec_round(10, Exact);
}
#[test]
#[should_panic]
fn sech_prec_fail() {
Float::ONE.sech_prec(0);
}
#[test]
#[should_panic]
fn sech_round_fail() {
Float::ONE.sech_round(Exact);
}
#[allow(clippy::needless_pass_by_value)]
fn sech_prec_round_properties_helper(x: Float, prec: u64, rm: RoundingMode) {
let (c, o) = x.clone().sech_prec_round(prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.sech_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.sech_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_sech_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).sech_prec_round(prec, rm);
assert_eq!(ComparableFloatRef(&c_neg), ComparableFloatRef(&c));
assert_eq!(o_neg, o);
if !x.is_nan() {
assert!((0u32..=1u32).contains(&c));
assert!(c.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.sech_prec_round_ref(prec, rm2);
assert_eq!(ComparableFloat(c2), ComparableFloat(c.clone()));
assert_eq!(o2, Equal);
}
} else {
assert_panic!(x.sech_prec_round_ref(prec, Exact));
}
}
#[test]
fn sech_prec_round_properties() {
float_unsigned_rounding_mode_triple_gen_var_36().test_properties(|(x, prec, rm)| {
sech_prec_round_properties_helper(x, prec, rm);
});
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::NAN.sech_prec_round(prec, rm);
assert!(c.is_nan());
assert_eq!(o, Equal);
let (c, o) = Float::INFINITY.sech_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::ZERO));
assert_eq!(o, Equal);
let (c, o) = Float::NEGATIVE_INFINITY.sech_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::ZERO));
assert_eq!(o, Equal);
let (c, o) = Float::ZERO.sech_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::one_prec(prec)));
assert_eq!(o, Equal);
let (c, o) = Float::NEGATIVE_ZERO.sech_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::one_prec(prec)));
assert_eq!(o, Equal);
});
}
#[test]
fn sech_round_properties() {
float_rounding_mode_pair_gen_var_47().test_properties(|(x, rm)| {
let (c, o) = x.clone().sech_round(rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.sech_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.sech_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.sech_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_sech_round(&rug::Float::exact_from(&x), rug_rm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
});
}
#[test]
fn sech_prec_properties() {
float_unsigned_pair_gen_var_1().test_properties(|(x, prec)| {
let (c, o) = x.clone().sech_prec(prec);
assert!(c.is_valid());
let (c_alt, o_alt) = x.sech_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.sech_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.sech_prec_round_ref(prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (rug_c, rug_o) = rug_sech_prec(&rug::Float::exact_from(&x), prec);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
});
}
#[test]
fn sech_properties() {
float_gen().test_properties(|x| {
let c = x.clone().sech();
assert!(c.is_valid());
let c_alt = (&x).sech();
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
let mut x_alt = x.clone();
x_alt.sech_assign();
assert!(x_alt.is_valid());
assert_eq!(ComparableFloatRef(&x_alt), ComparableFloatRef(&c));
let c_alt = x.sech_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_sech(
&rug::Float::exact_from(&x)
))),
ComparableFloatRef(&c)
);
assert_eq!(ComparableFloatRef(&(-&x).sech()), ComparableFloatRef(&c));
if !x.is_nan() {
assert!(c.is_sign_positive());
}
});
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_sech() {
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_sech(x)), NiceFloat(out));
}
test::<f32>(f32::NAN, f32::NAN);
test::<f32>(f32::INFINITY, 0.0);
test::<f32>(f32::NEGATIVE_INFINITY, 0.0);
test::<f32>(0.0, 1.0);
test::<f32>(-0.0, 1.0);
test::<f32>(1.0, 0.6480543);
test::<f32>(-1.0, 0.6480543);
test::<f32>(0.5, 0.8868189);
test::<f32>(2.0, 0.26580223);
test::<f32>(10.0, 0.00009079986);
test::<f32>(88.0, 1.2109204e-38);
test::<f32>(89.0, 4.454728e-39);
test::<f32>(95.0, 1.1042e-41);
test::<f32>(100.0, 7.4e-44);
test::<f32>(104.0, 1.0e-45);
test::<f32>(1.0e-20, 1.0);
test::<f32>(1.0e-45, 1.0);
test::<f32>(3.4028235e38, 0.0);
test::<f64>(f64::NAN, f64::NAN);
test::<f64>(f64::INFINITY, 0.0);
test::<f64>(f64::NEGATIVE_INFINITY, 0.0);
test::<f64>(0.0, 1.0);
test::<f64>(-0.0, 1.0);
test::<f64>(1.0, 0.6480542736638853);
test::<f64>(-1.0, 0.6480542736638853);
test::<f64>(0.5, 0.8868188839700739);
test::<f64>(2.0, 0.26580222883407967);
test::<f64>(10.0, 0.00009079985933781725);
test::<f64>(700.0, 1.971935308751954e-304);
test::<f64>(710.0, 8.95257245135026e-309);
test::<f64>(720.0, 4.06446160484e-313);
test::<f64>(744.0, 1.5e-323);
test::<f64>(745.0, 5.0e-324);
test::<f64>(746.0, 0.0);
test::<f64>(1.0e-200, 1.0);
test::<f64>(5.0e-324, 1.0);
test::<f64>(1.7976931348623157e308, 0.0);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_sech_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_sech(x);
assert_eq!(c.is_nan(), x.is_nan());
if !x.is_nan() {
assert!(c >= T::ZERO && c <= T::ONE);
assert!(c.is_sign_positive());
assert_eq!(NiceFloat(primitive_float_sech(-x)), NiceFloat(c));
}
if x.is_finite() {
let rug_c: T = round_once_to_primitive(|p| {
<Float as From<&rug::Float>>::from(
&rug_sech_prec(&rug::Float::exact_from(&Float::from(x)), p).0,
)
});
assert_eq!(NiceFloat(rug_c), NiceFloat(c));
}
});
}
#[test]
fn primitive_float_sech_properties() {
apply_fn_to_primitive_floats!(primitive_float_sech_properties_helper);
}
#[test]
fn test_sech_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::sech_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::sech_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_sech_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, "0.50", "0x0.8#1", Less);
test("3/5", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("3/5", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("3/5", 10, Floor, "0.84277", "0x0.d7c#10", Less);
test("3/5", 10, Ceiling, "0.84375", "0x0.d80#10", Greater);
test("3/5", 10, Nearest, "0.84375", "0x0.d80#10", Greater);
test(
"3/5",
100,
Floor,
"0.84355068762180664157749873109046",
"0x0.d7f2f017da9de104a6d765766#100",
Less,
);
test(
"3/5",
100,
Ceiling,
"0.84355068762180664157749873109125",
"0x0.d7f2f017da9de104a6d765767#100",
Greater,
);
test(
"3/5",
100,
Nearest,
"0.84355068762180664157749873109125",
"0x0.d7f2f017da9de104a6d765767#100",
Greater,
);
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, "1.0", "0x1.0#1", Greater);
test("-3/5", 10, Floor, "0.84277", "0x0.d7c#10", Less);
test("-3/5", 10, Ceiling, "0.84375", "0x0.d80#10", Greater);
test("-3/5", 10, Nearest, "0.84375", "0x0.d80#10", Greater);
test(
"-3/5",
100,
Floor,
"0.84355068762180664157749873109046",
"0x0.d7f2f017da9de104a6d765766#100",
Less,
);
test(
"-3/5",
100,
Ceiling,
"0.84355068762180664157749873109125",
"0x0.d7f2f017da9de104a6d765767#100",
Greater,
);
test(
"-3/5",
100,
Nearest,
"0.84355068762180664157749873109125",
"0x0.d7f2f017da9de104a6d765767#100",
Greater,
);
test("1/3", 1, Floor, "0.50", "0x0.8#1", Less);
test("1/3", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("1/3", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1/3", 10, Floor, "0.94629", "0x0.f24#10", Less);
test("1/3", 10, Ceiling, "0.94727", "0x0.f28#10", Greater);
test("1/3", 10, Nearest, "0.94727", "0x0.f28#10", Greater);
test(
"1/3",
100,
Floor,
"0.94690525376349792655895228013934",
"0x0.f26861f95326637981841f9c9#100",
Less,
);
test(
"1/3",
100,
Ceiling,
"0.94690525376349792655895228014013",
"0x0.f26861f95326637981841f9ca#100",
Greater,
);
test(
"1/3",
100,
Nearest,
"0.94690525376349792655895228014013",
"0x0.f26861f95326637981841f9ca#100",
Greater,
);
test("22/7", 1, Floor, "0.062", "0x0.1#1", Less);
test("22/7", 1, Ceiling, "0.12", "0x0.2#1", Greater);
test("22/7", 1, Nearest, "0.062", "0x0.1#1", Less);
test("22/7", 10, Floor, "0.086060", "0x0.1608#10", Less);
test("22/7", 10, Ceiling, "0.086182", "0x0.1610#10", Greater);
test("22/7", 10, Nearest, "0.086182", "0x0.1610#10", Greater);
test(
"22/7",
100,
Floor,
"0.086158129536979492276196616870947",
"0x0.160e758ca556fc438352ae2a42#100",
Less,
);
test(
"22/7",
100,
Ceiling,
"0.086158129536979492276196616871046",
"0x0.160e758ca556fc438352ae2a44#100",
Greater,
);
test(
"22/7",
100,
Nearest,
"0.086158129536979492276196616870947",
"0x0.160e758ca556fc438352ae2a42#100",
Less,
);
test("100", 1, Floor, "4.5e-44", "0x1.0E-36#1", Less);
test("100", 1, Ceiling, "9.0e-44", "0x2.0E-36#1", Greater);
test("100", 1, Nearest, "9.0e-44", "0x2.0E-36#1", Greater);
test("100", 10, Floor, "7.4356e-44", "0x1.a88E-36#10", Less);
test("100", 10, Ceiling, "7.4444e-44", "0x1.a90E-36#10", Greater);
test("100", 10, Nearest, "7.4444e-44", "0x1.a90E-36#10", Greater);
test(
"100",
100,
Floor,
"7.4401519520416719259193916077216e-44",
"0x1.a8c1f14e2af5caf3dd91375c6E-36#100",
Less,
);
test(
"100",
100,
Ceiling,
"7.4401519520416719259193916077287e-44",
"0x1.a8c1f14e2af5caf3dd91375c8E-36#100",
Greater,
);
test(
"100",
100,
Nearest,
"7.4401519520416719259193916077287e-44",
"0x1.a8c1f14e2af5caf3dd91375c8E-36#100",
Greater,
);
test("-100", 1, Floor, "4.5e-44", "0x1.0E-36#1", Less);
test("-100", 1, Ceiling, "9.0e-44", "0x2.0E-36#1", Greater);
test("-100", 1, Nearest, "9.0e-44", "0x2.0E-36#1", Greater);
test("-100", 10, Floor, "7.4356e-44", "0x1.a88E-36#10", Less);
test("-100", 10, Ceiling, "7.4444e-44", "0x1.a90E-36#10", Greater);
test("-100", 10, Nearest, "7.4444e-44", "0x1.a90E-36#10", Greater);
test(
"-100",
100,
Floor,
"7.4401519520416719259193916077216e-44",
"0x1.a8c1f14e2af5caf3dd91375c6E-36#100",
Less,
);
test(
"-100",
100,
Ceiling,
"7.4401519520416719259193916077287e-44",
"0x1.a8c1f14e2af5caf3dd91375c8E-36#100",
Greater,
);
test(
"-100",
100,
Nearest,
"7.4401519520416719259193916077287e-44",
"0x1.a8c1f14e2af5caf3dd91375c8E-36#100",
Greater,
);
test("1/1000", 1, Floor, "0.50", "0x0.8#1", Less);
test("1/1000", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("1/1000", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1/1000", 10, Floor, "0.99902", "0x0.ffc#10", Less);
test("1/1000", 10, Ceiling, "1.0000", "0x1.000#10", Greater);
test("1/1000", 10, Nearest, "1.0000", "0x1.000#10", Greater);
test(
"1/1000",
100,
Floor,
"0.99999950000020833324861114546071",
"0x0.fffff79c846a490757e6daafb#100",
Less,
);
test(
"1/1000",
100,
Ceiling,
"0.99999950000020833324861114546150",
"0x0.fffff79c846a490757e6daafc#100",
Greater,
);
test(
"1/1000",
100,
Nearest,
"0.99999950000020833324861114546150",
"0x0.fffff79c846a490757e6daafc#100",
Greater,
);
test("-1/1000000", 1, Floor, "0.50", "0x0.8#1", Less);
test("-1/1000000", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("-1/1000000", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("-1/1000000", 10, Floor, "0.99902", "0x0.ffc#10", Less);
test("-1/1000000", 10, Ceiling, "1.0000", "0x1.000#10", Greater);
test("-1/1000000", 10, Nearest, "1.0000", "0x1.000#10", Greater);
test(
"-1/1000000",
100,
Floor,
"0.99999999999950000000000020833323",
"0x0.ffffffffff734333f690eff11#100",
Less,
);
test(
"-1/1000000",
100,
Ceiling,
"0.99999999999950000000000020833402",
"0x0.ffffffffff734333f690eff12#100",
Greater,
);
test(
"-1/1000000",
100,
Nearest,
"0.99999999999950000000000020833323",
"0x0.ffffffffff734333f690eff11#100",
Less,
);
test("1/100000000000000000000", 1, Floor, "0.50", "0x0.8#1", Less);
test(
"1/100000000000000000000",
1,
Ceiling,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/100000000000000000000",
1,
Nearest,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/100000000000000000000",
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1/100000000000000000000",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/100000000000000000000",
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/100000000000000000000",
100,
Floor,
"0.99999999999999999999999999999921",
"0x0.fffffffffffffffffffffffff#100",
Less,
);
test(
"1/100000000000000000000",
100,
Ceiling,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"1/100000000000000000000",
100,
Nearest,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"1488522235/2",
1,
Floor,
"4.8e-323228497",
"0x2.0E-268435456#1",
Less,
);
test(
"1488522235/2",
1,
Ceiling,
"9.5e-323228497",
"0x4.0E-268435456#1",
Greater,
);
test(
"1488522235/2",
1,
Nearest,
"9.5e-323228497",
"0x4.0E-268435456#1",
Greater,
);
test(
"1488522235/2",
10,
Floor,
"7.5014e-323228497",
"0x3.26E-268435456#10",
Less,
);
test(
"1488522235/2",
10,
Ceiling,
"7.5107e-323228497",
"0x3.27E-268435456#10",
Greater,
);
test(
"1488522235/2",
10,
Nearest,
"7.5107e-323228497",
"0x3.27E-268435456#10",
Greater,
);
test(
"1488522235/2",
100,
Floor,
"7.5098673083218467310380527281516e-323228497",
"0x3.26ea18e02da8f8a2632086ef8E-268435456#100",
Less,
);
test(
"1488522235/2",
100,
Ceiling,
"7.5098673083218467310380527281592e-323228497",
"0x3.26ea18e02da8f8a2632086efcE-268435456#100",
Greater,
);
test(
"1488522235/2",
100,
Nearest,
"7.5098673083218467310380527281516e-323228497",
"0x3.26ea18e02da8f8a2632086ef8E-268435456#100",
Less,
);
test(
"7442611177/10",
1,
Floor,
"4.8e-323228497",
"0x2.0E-268435456#1",
Less,
);
test(
"7442611177/10",
1,
Ceiling,
"9.5e-323228497",
"0x4.0E-268435456#1",
Greater,
);
test(
"7442611177/10",
1,
Nearest,
"4.8e-323228497",
"0x2.0E-268435456#1",
Less,
);
test(
"7442611177/10",
10,
Floor,
"6.1426e-323228497",
"0x2.94E-268435456#10",
Less,
);
test(
"7442611177/10",
10,
Ceiling,
"6.1519e-323228497",
"0x2.95E-268435456#10",
Greater,
);
test(
"7442611177/10",
10,
Nearest,
"6.1519e-323228497",
"0x2.95E-268435456#10",
Greater,
);
test(
"7442611177/10",
100,
Floor,
"6.1485593168580621515208966267134e-323228497",
"0x2.94a54a8d64062c460adda8654E-268435456#100",
Less,
);
test(
"7442611177/10",
100,
Ceiling,
"6.1485593168580621515208966267209e-323228497",
"0x2.94a54a8d64062c460adda8658E-268435456#100",
Greater,
);
test(
"7442611177/10",
100,
Nearest,
"6.1485593168580621515208966267134e-323228497",
"0x2.94a54a8d64062c460adda8654E-268435456#100",
Less,
);
test(
"-7442611185/10",
1,
Floor,
"2.4e-323228497",
"0x1.0E-268435456#1",
Less,
);
test(
"-7442611185/10",
1,
Ceiling,
"4.8e-323228497",
"0x2.0E-268435456#1",
Greater,
);
test(
"-7442611185/10",
1,
Nearest,
"2.4e-323228497",
"0x1.0E-268435456#1",
Less,
);
test(
"-7442611185/10",
10,
Floor,
"2.7595e-323228497",
"0x1.288E-268435456#10",
Less,
);
test(
"-7442611185/10",
10,
Ceiling,
"2.7641e-323228497",
"0x1.290E-268435456#10",
Greater,
);
test(
"-7442611185/10",
10,
Nearest,
"2.7641e-323228497",
"0x1.290E-268435456#10",
Greater,
);
test(
"-7442611185/10",
100,
Floor,
"2.7627257886571247097149806987996e-323228497",
"0x1.28d8e45434c7216121ffbfc56E-268435456#100",
Less,
);
test(
"-7442611185/10",
100,
Ceiling,
"2.7627257886571247097149806988033e-323228497",
"0x1.28d8e45434c7216121ffbfc58E-268435456#100",
Greater,
);
test(
"-7442611185/10",
100,
Nearest,
"2.7627257886571247097149806988033e-323228497",
"0x1.28d8e45434c7216121ffbfc58E-268435456#100",
Greater,
);
test("744261119", 1, Floor, "0.0", "0x0.0", Less);
test(
"744261119",
1,
Ceiling,
"2.4e-323228497",
"0x1.0E-268435456#1",
Greater,
);
test(
"744261119",
1,
Nearest,
"2.4e-323228497",
"0x1.0E-268435456#1",
Greater,
);
test("744261119", 10, Floor, "0.0", "0x0.0", Less);
test(
"744261119",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test(
"744261119",
10,
Nearest,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test("744261119", 100, Floor, "0.0", "0x0.0", Less);
test(
"744261119",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test(
"744261119",
100,
Nearest,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test("7442611196/10", 1, Floor, "0.0", "0x0.0", Less);
test(
"7442611196/10",
1,
Ceiling,
"2.4e-323228497",
"0x1.0E-268435456#1",
Greater,
);
test("7442611196/10", 1, Nearest, "0.0", "0x0.0", Less);
test("7442611196/10", 10, Floor, "0.0", "0x0.0", Less);
test(
"7442611196/10",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test("7442611196/10", 10, Nearest, "0.0", "0x0.0", Less);
test("7442611196/10", 100, Floor, "0.0", "0x0.0", Less);
test(
"7442611196/10",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test("7442611196/10", 100, Nearest, "0.0", "0x0.0", Less);
test("744261120", 1, Floor, "0.0", "0x0.0", Less);
test(
"744261120",
1,
Ceiling,
"2.4e-323228497",
"0x1.0E-268435456#1",
Greater,
);
test("744261120", 1, Nearest, "0.0", "0x0.0", Less);
test("744261120", 10, Floor, "0.0", "0x0.0", Less);
test(
"744261120",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test("744261120", 10, Nearest, "0.0", "0x0.0", Less);
test("744261120", 100, Floor, "0.0", "0x0.0", Less);
test(
"744261120",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test("744261120", 100, Nearest, "0.0", "0x0.0", Less);
test("10000000000", 1, Floor, "0.0", "0x0.0", Less);
test(
"10000000000",
1,
Ceiling,
"2.4e-323228497",
"0x1.0E-268435456#1",
Greater,
);
test("10000000000", 1, Nearest, "0.0", "0x0.0", Less);
test("10000000000", 10, Floor, "0.0", "0x0.0", Less);
test(
"10000000000",
10,
Ceiling,
"2.3826e-323228497",
"0x1.000E-268435456#10",
Greater,
);
test("10000000000", 10, Nearest, "0.0", "0x0.0", Less);
test("10000000000", 100, Floor, "0.0", "0x0.0", Less);
test(
"10000000000",
100,
Ceiling,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test("10000000000", 100, Nearest, "0.0", "0x0.0", Less);
test(
"1/1000",
100,
Down,
"0.99999950000020833324861114546071",
"0x0.fffff79c846a490757e6daafb#100",
Less,
);
test("744261119", 100, Down, "0.0", "0x0.0", Less);
test(
"1/1000",
100,
Up,
"0.99999950000020833324861114546150",
"0x0.fffff79c846a490757e6daafc#100",
Greater,
);
test(
"744261119",
100,
Up,
"2.3825649048879510732161697817327e-323228497",
"0x1.0000000000000000000000000E-268435456#100",
Greater,
);
test("2/13", 7, Floor, "0.9844", "0x0.fc#7", Less);
test("2/13", 7, Ceiling, "0.9922", "0x0.fe#7", Greater);
test("2/13", 7, Nearest, "0.9922", "0x0.fe#7", Greater);
}
#[test]
fn test_sech_rational_extreme() {
let x = Rational::power_of_2(-(1i64 << 30) - 10);
for (rm, out, o_out) in [
(Floor, "0.99902", Less),
(Down, "0.99902", Less),
(Nearest, "1.0000", Greater),
(Ceiling, "1.0000", Greater),
(Up, "1.0000", Greater),
] {
let (c, o) = Float::sech_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::sech_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::sech_rational_prec_round_ref(&x, 10, Nearest);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::ZERO));
assert_eq!(o, Less);
let (c, o) = Float::sech_rational_prec_round(-x, 10, Up);
assert_eq!(
ComparableFloat(c),
ComparableFloat(Float::min_positive_value_prec(10))
);
assert_eq!(o, Greater);
}
#[test]
#[should_panic]
fn sech_rational_prec_fail() {
Float::sech_rational_prec(Rational::ONE, 0);
}
#[test]
#[should_panic]
fn sech_rational_prec_ref_fail() {
Float::sech_rational_prec_ref(&Rational::ONE, 0);
}
#[test]
#[should_panic]
fn sech_rational_prec_round_fail_1() {
Float::sech_rational_prec_round(Rational::ONE, 0, Floor);
}
#[test]
#[should_panic]
fn sech_rational_prec_round_fail_2() {
Float::sech_rational_prec_round(Rational::ONE, 10, Exact);
}
#[test]
#[should_panic]
fn sech_rational_prec_round_ref_fail() {
Float::sech_rational_prec_round_ref(&Rational::ONE, 10, Exact);
}
#[allow(clippy::needless_pass_by_value)]
fn sech_rational_prec_round_properties_helper(x: Rational, prec: u64, rm: RoundingMode) {
let (c, o) = Float::sech_rational_prec_round(x.clone(), prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = Float::sech_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!((0u32..=1u32).contains(&c));
let (c_neg, o_neg) = Float::sech_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_sech_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::sech_rational_prec_round_ref(&x, prec, rm);
assert_eq!(ComparableFloatRef(&s), ComparableFloatRef(&c));
assert_eq!(oo, Equal);
}
} else {
assert_panic!(Float::sech_rational_prec_round_ref(&x, prec, Exact));
}
}
#[test]
fn sech_rational_prec_round_properties() {
rational_unsigned_rounding_mode_triple_gen_var_10().test_properties(|(x, prec, rm)| {
sech_rational_prec_round_properties_helper(x, prec, rm);
});
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::sech_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 sech_rational_prec_properties_helper(x: Rational, prec: u64) {
let (c, o) = Float::sech_rational_prec(x.clone(), prec);
assert!(c.is_valid());
let (c_alt, o_alt) = Float::sech_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::sech_rational_prec_round_ref(&x, prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
assert!((0u32..=1u32).contains(&c));
let (rug_c, rug_o) = rug_sech_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.sech_prec(prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
}
}
#[test]
fn sech_rational_prec_properties() {
rational_unsigned_pair_gen_var_3().test_properties(|(x, prec)| {
sech_rational_prec_properties_helper(x, prec);
});
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_sech_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_sech_rational::<T>(&x)),
NiceFloat(out)
);
}
test::<f32>("0", 1.0);
test::<f32>("1", 0.6480543);
test::<f32>("-1", 0.6480543);
test::<f32>("1/3", 0.94690526);
test::<f32>("22/7", 0.08615813);
test::<f32>("95", 1.1042e-41);
test::<f32>("100", 7.4e-44);
test::<f32>("104", 1.0e-45);
test::<f32>("710", 0.0);
test::<f32>("720", 0.0);
test::<f32>("-745", 0.0);
test::<f32>("7451/10", 0.0);
test::<f32>("746", 0.0);
test::<f32>("10000", 0.0);
test::<f32>("1/100000000000000000000", 1.0);
test::<f64>("0", 1.0);
test::<f64>("1", 0.6480542736638853);
test::<f64>("-1", 0.6480542736638853);
test::<f64>("1/3", 0.9469052537634979);
test::<f64>("22/7", 0.08615812953697949);
test::<f64>("95", 1.1042164554057065e-41);
test::<f64>("100", 7.440151952041672e-44);
test::<f64>("104", 1.3627113643090597e-45);
test::<f64>("710", 8.95257245135026e-309);
test::<f64>("720", 4.06446160484e-313);
test::<f64>("-745", 5.0e-324);
test::<f64>("7451/10", 5.0e-324);
test::<f64>("746", 0.0);
test::<f64>("10000", 0.0);
test::<f64>("1/100000000000000000000", 1.0);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_sech_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_sech_rational::<T>(&x);
assert!(c >= T::ZERO && c <= T::ONE);
assert_eq!(
NiceFloat(primitive_float_sech_rational::<T>(&-&x)),
NiceFloat(c)
);
let rug_c: T = round_once_to_primitive(|p| {
<Float as From<&rug::Float>>::from(&rug_sech_rational_prec(&x, p).0)
});
assert_eq!(NiceFloat(rug_c), NiceFloat(c));
});
primitive_float_gen::<T>().test_properties(|x| {
if x.is_finite() {
assert_eq!(
NiceFloat(primitive_float_sech_rational::<T>(&Rational::exact_from(x))),
NiceFloat(primitive_float_sech(x))
);
}
});
}
#[test]
fn primitive_float_sech_rational_properties() {
apply_fn_to_primitive_floats!(primitive_float_sech_rational_properties_helper);
}