use core::cmp::Ordering::{self, *};
use malachite_base::num::arithmetic::traits::{Cos, CosAssign, PowerOf2};
use malachite_base::num::basic::floats::PrimitiveFloat;
use malachite_base::num::basic::traits::{
Infinity, NaN, NegativeInfinity, NegativeZero, One, Zero,
};
use malachite_base::num::comparison::traits::PartialOrdAbs;
use malachite_base::num::conversion::traits::{ExactFrom, RoundingFrom};
use malachite_base::num::float::NiceFloat;
use malachite_base::num::logic::traits::SignificantBits;
use malachite_base::rounding_modes::RoundingMode::{self, *};
use malachite_base::rounding_modes::exhaustive::exhaustive_rounding_modes;
use malachite_base::test_util::generators::{
primitive_float_gen, primitive_float_unsigned_pair_gen_var_1,
unsigned_rounding_mode_pair_gen_var_3,
};
use malachite_float::float::arithmetic::cos::{
primitive_float_cos, primitive_float_cos_pi, primitive_float_cos_pi_rational,
primitive_float_cos_rational, primitive_float_cos_with_period,
primitive_float_cos_with_period_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::cos::{
rug_cos, rug_cos_pi_prec_round, rug_cos_pi_rational_prec_round, rug_cos_prec,
rug_cos_prec_round, rug_cos_rational_prec, rug_cos_rational_prec_round, rug_cos_round,
rug_cos_with_period_prec, rug_cos_with_period_prec_round, rug_cos_with_period_rational_prec,
rug_cos_with_period_rational_prec_round,
};
use malachite_float::test_util::generators::{
float_gen, float_rounding_mode_pair_gen_var_47, float_unsigned_pair_gen_var_1,
float_unsigned_pair_gen_var_2, float_unsigned_rounding_mode_triple_gen_var_36,
float_unsigned_rounding_mode_triple_gen_var_37, float_unsigned_rounding_mode_triple_gen_var_38,
float_unsigned_unsigned_rounding_mode_quadruple_gen_var_15,
float_unsigned_unsigned_rounding_mode_quadruple_gen_var_16,
float_unsigned_unsigned_triple_gen_var_1, rational_unsigned_rounding_mode_triple_gen_var_10,
rational_unsigned_unsigned_rounding_mode_quadruple_gen_var_4,
};
use malachite_float::{ComparableFloat, ComparableFloatRef, Float};
use malachite_q::Rational;
use malachite_q::test_util::generators::{
rational_gen, rational_unsigned_pair_gen_var_1, rational_unsigned_pair_gen_var_3,
};
use std::panic::catch_unwind;
use std::str::FromStr;
#[test]
fn test_cos_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().cos_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.cos_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.cos_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_cos_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, "NaN", "NaN", Equal);
test("-Infinity", "-Infinity", 1, Nearest, "NaN", "NaN", 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.54004", "0x0.8a4#10", Less);
test(
"1.0",
"0x1.0#1",
10,
Ceiling,
"0.54102",
"0x0.8a8#10",
Greater,
);
test("1.0", "0x1.0#1", 10, Nearest, "0.54004", "0x0.8a4#10", Less);
test(
"1.0",
"0x1.0#1",
100,
Floor,
"0.54030230586813971740093660744256",
"0x0.8a51407da8345c91c2466d976#100",
Less,
);
test(
"1.0",
"0x1.0#1",
100,
Ceiling,
"0.54030230586813971740093660744335",
"0x0.8a51407da8345c91c2466d977#100",
Greater,
);
test(
"1.0",
"0x1.0#1",
100,
Nearest,
"0.54030230586813971740093660744335",
"0x0.8a51407da8345c91c2466d977#100",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
10,
Nearest,
"0.54004",
"0x0.8a4#10",
Less,
);
test(
"2.0",
"0x2.0#1",
10,
Nearest,
"-0.41602",
"-0x0.6a8#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
10,
Nearest,
"-0.99023",
"-0x0.fd8#10",
Less,
);
test(
"4.0",
"0x4.0#1",
10,
Nearest,
"-0.65332",
"-0x0.a74#10",
Greater,
);
test(
"4.0",
"0x4.0#1",
100,
Nearest,
"-0.65364362086361191463916818309786",
"-0x0.a7553036d926062336d0e16e4#100",
Less,
);
test(
"100.0",
"0x64.0#5",
10,
Nearest,
"0.86230",
"0x0.dcc#10",
Less,
);
test(
"100.0",
"0x64.0#5",
100,
Floor,
"0.86231887228768393410193851395020",
"0x0.dcc0edfb32fefb1fa19b9b30b#100",
Less,
);
test(
"100.0",
"0x64.0#5",
100,
Ceiling,
"0.86231887228768393410193851395099",
"0x0.dcc0edfb32fefb1fa19b9b30c#100",
Greater,
);
test(
"1.00000e6",
"0xf.424E+4#14",
64,
Nearest,
"0.936752127533144786917",
"0x0.efcefcc836996357#64",
Less,
);
test(
"0.50",
"0x0.8#1",
50,
Nearest,
"0.87758256189037276",
"0x0.e0a94032dbea8#50",
Greater,
);
test(
"0.102",
"0x0.1a#4",
50,
Nearest,
"0.99484696102354064",
"0x0.feae4a5a1f000#50",
Greater,
);
test(
"1.000e-10",
"0x6.eE-9#7",
50,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#50",
Greater,
);
test(
"1.000e-10",
"0x6.eE-9#7",
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.000e-10",
"0x6.eE-9#7",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.570796326794896600",
"0x1.921fb54442d183#57",
53,
Nearest,
"1.9598976533924290e-17",
"0x1.69898cc51701cE-14#53",
Greater,
);
test(
"3.14159265358979289",
"0x3.243f6a8885a2f#54",
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Less,
);
test(
"6.28318530717958579",
"0x6.487ed5110b45e#54",
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"9.979e99",
"0x1.24E+83#7",
53,
Nearest,
"-0.42980316367459315",
"-0x0.6e079483b32060#53",
Greater,
);
test("3.0", "0x3.0#2", 1, Nearest, "-1.0", "-0x1.0#1", Less);
test("3.0", "0x3.0#2", 1, Floor, "-1.0", "-0x1.0#1", Less);
test("3.0", "0x3.0#2", 1, Ceiling, "-0.50", "-0x0.8#1", Greater);
test("3.0", "0x3.0#2", 2, Nearest, "-1.0", "-0x1.0#2", Less);
test("0.25", "0x0.4#1", 1, Down, "0.50", "0x0.8#1", Less);
test("1.0", "0x1.0#1", 1, Down, "0.50", "0x0.8#1", Less);
test("2.0", "0x2.0#1", 1, Down, "-0.25", "-0x0.4#1", Greater);
test("4.0", "0x4.0#1", 1, Down, "-0.50", "-0x0.8#1", Greater);
test(
"-3.495934488151859089160804055e56",
"-0xe.41ed086a5791d9e5b2924E+46#87",
2,
Down,
"0.75",
"0x0.c#2",
Less,
);
test(
"6.28318536",
"0x6.487ed6#26",
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.5707963267948966",
"0x1.921fb54442d18#53",
53,
Nearest,
"6.1232339957367660e-17",
"0x4.69898cc51701cE-14#53",
Greater,
);
test(
"1.5707963267948966192313216916397514420985846996875529104874722",
"0x1.921fb54442d18469898cc51701b839a252049c1114cf98e804#200",
100,
Floor,
"5.7099684971243490026437400060191e-62",
"0x1.77d4c76273644a29410f31c68E-51#100",
Less,
);
test(
"4.7123889803846898576939650749192543286",
"0x4.b65f1fccc8748d3c9ca64f450528b0#120",
120,
Ceiling,
"2.3305317247657495256428231620634736190e-36",
"0x3.1909f22bccc1913547f3b9881a9d8cE-30#120",
Greater,
);
test(
"3.14159265358979323851",
"0x3.243f6a8885a308d4#64",
64,
Nearest,
"-1.00000000000000000000",
"-0x1.0000000000000000#64",
Less,
);
}
#[test]
#[should_panic]
fn cos_prec_round_fail() {
Float::ONE.cos_prec_round(0, Nearest);
}
#[test]
#[should_panic]
fn cos_prec_round_exact_fail() {
Float::ONE.cos_prec_round(10, Exact);
}
#[test]
#[should_panic]
fn cos_prec_fail() {
Float::ONE.cos_prec(0);
}
#[test]
#[should_panic]
fn cos_round_fail() {
Float::ONE.cos_round(Exact);
}
#[allow(clippy::needless_pass_by_value)]
fn cos_prec_round_properties_helper(x: Float, prec: u64, rm: RoundingMode) {
let (c, o) = x.clone().cos_prec_round(prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.cos_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.cos_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_cos_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).cos_prec_round(prec, rm);
assert_eq!(ComparableFloatRef(&c_neg), ComparableFloatRef(&c));
assert_eq!(o_neg, o);
if c.is_finite() {
assert!(c.le_abs(&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.cos_prec_round_ref(prec, rm2);
assert_eq!(
ComparableFloat(c2.abs_negative_zero_ref()),
ComparableFloat(c.abs_negative_zero_ref())
);
assert_eq!(o2, Equal);
}
} else {
assert_panic!(x.cos_prec_round_ref(prec, Exact));
}
}
#[test]
fn cos_prec_round_properties() {
float_unsigned_rounding_mode_triple_gen_var_36().test_properties(|(x, prec, rm)| {
cos_prec_round_properties_helper(x, prec, rm);
});
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::NAN.cos_prec_round(prec, rm);
assert!(c.is_nan());
assert_eq!(o, Equal);
let (c, o) = Float::INFINITY.cos_prec_round(prec, rm);
assert!(c.is_nan());
assert_eq!(o, Equal);
let (c, o) = Float::NEGATIVE_INFINITY.cos_prec_round(prec, rm);
assert!(c.is_nan());
assert_eq!(o, Equal);
let (c, o) = Float::ZERO.cos_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::one_prec(prec)));
assert_eq!(o, Equal);
let (c, o) = Float::NEGATIVE_ZERO.cos_prec_round(prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::one_prec(prec)));
assert_eq!(o, Equal);
});
}
#[test]
fn cos_round_properties() {
float_rounding_mode_pair_gen_var_47().test_properties(|(x, rm)| {
let (c, o) = x.clone().cos_round(rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.cos_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.cos_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.cos_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_cos_round(&rug::Float::exact_from(&x), rug_rm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
});
}
#[test]
fn cos_prec_properties() {
float_unsigned_pair_gen_var_1().test_properties(|(x, prec)| {
let (c, o) = x.clone().cos_prec(prec);
assert!(c.is_valid());
let (c_alt, o_alt) = x.cos_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.cos_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.cos_prec_round_ref(prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (rug_c, rug_o) = rug_cos_prec(&rug::Float::exact_from(&x), prec);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
});
}
#[test]
fn cos_properties() {
float_gen().test_properties(|x| {
let c = x.clone().cos();
assert!(c.is_valid());
let c_alt = (&x).cos();
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
let mut x_alt = x.clone();
x_alt.cos_assign();
assert!(x_alt.is_valid());
assert_eq!(ComparableFloatRef(&x_alt), ComparableFloatRef(&c));
let (c_alt, _) = x.cos_prec_round_ref(x.significant_bits(), Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(
ComparableFloatRef(&Float::from(&rug_cos(&rug::Float::exact_from(&x)))),
ComparableFloatRef(&c)
);
assert_eq!(ComparableFloatRef(&(-&x).cos()), ComparableFloatRef(&c));
if c.is_finite() {
assert!(c.le_abs(&1u32));
}
});
}
fn odd_multiple_of_half_pi(n: i64, prec: u64) -> Float {
Float::pi_prec(prec)
.0
.mul_prec_round(Float::from(n), prec + 64, Exact)
.0
>> 1u32
}
#[test]
fn test_cos_near_zero() {
let test = |n: i64, prec_x: u64, prec: u64, rm, out: &str, out_hex: &str, o_out: Ordering| {
let x = odd_multiple_of_half_pi(n, prec_x);
let (c, o) = x.cos_prec_round_ref(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 (rug_c, rug_o) = rug_cos_prec_round(
&rug::Float::exact_from(&x),
prec,
rug_round_try_from_rounding_mode(rm).unwrap(),
);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
};
test(1, 150, 1, Up, "-7.0e-46", "-0x4.0E-38#1", Less);
test(1, 150, 1, Floor, "-7.0e-46", "-0x4.0E-38#1", Less);
test(1, 150, 1, Ceiling, "-3.5e-46", "-0x2.0E-38#1", Greater);
test(1, 150, 1, Nearest, "-7.0e-46", "-0x4.0E-38#1", Less);
test(1, 150, 10, Down, "-6.8833e-46", "-0x3.eeE-38#10", Greater);
test(1, 150, 10, Up, "-6.8902e-46", "-0x3.efE-38#10", Less);
test(1, 150, 10, Floor, "-6.8902e-46", "-0x3.efE-38#10", Less);
test(
1,
150,
10,
Ceiling,
"-6.8833e-46",
"-0x3.eeE-38#10",
Greater,
);
test(1, 150, 10, Nearest, "-6.8902e-46", "-0x3.efE-38#10", Less);
test(
1,
150,
53,
Down,
"-6.8896173743304411e-46",
"-0x3.eeeb306717fbeE-38#53",
Greater,
);
test(
1,
150,
53,
Up,
"-6.8896173743304419e-46",
"-0x3.eeeb306717fc0E-38#53",
Less,
);
test(
1,
150,
53,
Floor,
"-6.8896173743304419e-46",
"-0x3.eeeb306717fc0E-38#53",
Less,
);
test(
1,
150,
53,
Ceiling,
"-6.8896173743304411e-46",
"-0x3.eeeb306717fbeE-38#53",
Greater,
);
test(
1,
150,
53,
Nearest,
"-6.8896173743304411e-46",
"-0x3.eeeb306717fbeE-38#53",
Greater,
);
test(
1,
150,
100,
Nearest,
"-6.8896173743304413174294781085918e-46",
"-0x3.eeeb306717fbe882b389d8c9cE-38#100",
Less,
);
test(1, 190, 1, Down, "2.5e-60", "0x4.0E-50#1", Less);
test(1, 190, 1, Up, "5.0e-60", "0x8.0E-50#1", Greater);
test(1, 190, 1, Floor, "2.5e-60", "0x4.0E-50#1", Less);
test(1, 190, 1, Ceiling, "5.0e-60", "0x8.0E-50#1", Greater);
test(1, 190, 1, Nearest, "2.5e-60", "0x4.0E-50#1", Less);
test(1, 190, 10, Down, "2.5427e-60", "0x4.16E-50#10", Less);
test(1, 190, 10, Up, "2.5475e-60", "0x4.18E-50#10", Greater);
test(1, 190, 10, Floor, "2.5427e-60", "0x4.16E-50#10", Less);
test(1, 190, 10, Ceiling, "2.5475e-60", "0x4.18E-50#10", Greater);
test(1, 190, 10, Nearest, "2.5475e-60", "0x4.18E-50#10", Greater);
test(
1,
190,
53,
Down,
"2.5463057961157001e-60",
"0x4.177d4c7627364E-50#53",
Less,
);
test(
1,
190,
53,
Up,
"2.5463057961157007e-60",
"0x4.177d4c7627368E-50#53",
Greater,
);
test(
1,
190,
53,
Floor,
"2.5463057961157001e-60",
"0x4.177d4c7627364E-50#53",
Less,
);
test(
1,
190,
53,
Ceiling,
"2.5463057961157007e-60",
"0x4.177d4c7627368E-50#53",
Greater,
);
test(
1,
190,
53,
Nearest,
"2.5463057961157001e-60",
"0x4.177d4c7627364E-50#53",
Less,
);
test(
1,
190,
100,
Nearest,
"2.5463057961157001728840630215730e-60",
"0x4.177d4c76273644a29410f31c8E-50#100",
Greater,
);
test(1, 200, 1, Down, "3.9e-62", "0x1.0E-51#1", Less);
test(1, 200, 1, Up, "7.8e-62", "0x2.0E-51#1", Greater);
test(1, 200, 1, Floor, "3.9e-62", "0x1.0E-51#1", Less);
test(1, 200, 1, Ceiling, "7.8e-62", "0x2.0E-51#1", Greater);
test(1, 200, 1, Nearest, "3.9e-62", "0x1.0E-51#1", Less);
test(1, 200, 10, Down, "5.7049e-62", "0x1.778E-51#10", Less);
test(1, 200, 10, Up, "5.7125e-62", "0x1.780E-51#10", Greater);
test(1, 200, 10, Floor, "5.7049e-62", "0x1.778E-51#10", Less);
test(1, 200, 10, Ceiling, "5.7125e-62", "0x1.780E-51#10", Greater);
test(1, 200, 10, Nearest, "5.7125e-62", "0x1.780E-51#10", Greater);
test(
1,
200,
53,
Down,
"5.7099684971243485e-62",
"0x1.77d4c76273644E-51#53",
Less,
);
test(
1,
200,
53,
Up,
"5.7099684971243493e-62",
"0x1.77d4c76273645E-51#53",
Greater,
);
test(
1,
200,
53,
Floor,
"5.7099684971243485e-62",
"0x1.77d4c76273644E-51#53",
Less,
);
test(
1,
200,
53,
Ceiling,
"5.7099684971243493e-62",
"0x1.77d4c76273645E-51#53",
Greater,
);
test(
1,
200,
53,
Nearest,
"5.7099684971243493e-62",
"0x1.77d4c76273645E-51#53",
Greater,
);
test(
1,
200,
100,
Nearest,
"5.7099684971243490026437400060191e-62",
"0x1.77d4c76273644a29410f31c68E-51#100",
Less,
);
test(3, 200, 1, Down, "-1.6e-61", "-0x4.0E-51#1", Greater);
test(3, 200, 1, Up, "-3.1e-61", "-0x8.0E-51#1", Less);
test(3, 200, 1, Floor, "-3.1e-61", "-0x8.0E-51#1", Less);
test(3, 200, 1, Ceiling, "-1.6e-61", "-0x4.0E-51#1", Greater);
test(3, 200, 1, Nearest, "-1.6e-61", "-0x4.0E-51#1", Greater);
test(3, 200, 10, Down, "-1.7107e-61", "-0x4.66E-51#10", Greater);
test(3, 200, 10, Up, "-1.7138e-61", "-0x4.68E-51#10", Less);
test(3, 200, 10, Floor, "-1.7138e-61", "-0x4.68E-51#10", Less);
test(
3,
200,
10,
Ceiling,
"-1.7107e-61",
"-0x4.66E-51#10",
Greater,
);
test(3, 200, 10, Nearest, "-1.7138e-61", "-0x4.68E-51#10", Less);
test(
3,
200,
53,
Down,
"-1.7129905491373045e-61",
"-0x4.677e56275a2ccE-51#53",
Greater,
);
test(
3,
200,
53,
Up,
"-1.7129905491373049e-61",
"-0x4.677e56275a2d0E-51#53",
Less,
);
test(
3,
200,
53,
Floor,
"-1.7129905491373049e-61",
"-0x4.677e56275a2d0E-51#53",
Less,
);
test(
3,
200,
53,
Ceiling,
"-1.7129905491373045e-61",
"-0x4.677e56275a2ccE-51#53",
Greater,
);
test(
3,
200,
53,
Nearest,
"-1.7129905491373045e-61",
"-0x4.677e56275a2ccE-51#53",
Greater,
);
test(
3,
200,
100,
Nearest,
"-1.7129905491373047007931220018057e-61",
"-0x4.677e56275a2cde7bc32d95538E-51#100",
Greater,
);
test(-1, 200, 1, Down, "3.9e-62", "0x1.0E-51#1", Less);
test(-1, 200, 1, Up, "7.8e-62", "0x2.0E-51#1", Greater);
test(-1, 200, 1, Floor, "3.9e-62", "0x1.0E-51#1", Less);
test(-1, 200, 1, Ceiling, "7.8e-62", "0x2.0E-51#1", Greater);
test(-1, 200, 1, Nearest, "3.9e-62", "0x1.0E-51#1", Less);
test(-1, 200, 10, Down, "5.7049e-62", "0x1.778E-51#10", Less);
test(-1, 200, 10, Up, "5.7125e-62", "0x1.780E-51#10", Greater);
test(-1, 200, 10, Floor, "5.7049e-62", "0x1.778E-51#10", Less);
test(
-1,
200,
10,
Ceiling,
"5.7125e-62",
"0x1.780E-51#10",
Greater,
);
test(
-1,
200,
10,
Nearest,
"5.7125e-62",
"0x1.780E-51#10",
Greater,
);
test(
-1,
200,
53,
Down,
"5.7099684971243485e-62",
"0x1.77d4c76273644E-51#53",
Less,
);
test(
-1,
200,
53,
Up,
"5.7099684971243493e-62",
"0x1.77d4c76273645E-51#53",
Greater,
);
test(
-1,
200,
53,
Floor,
"5.7099684971243485e-62",
"0x1.77d4c76273644E-51#53",
Less,
);
test(
-1,
200,
53,
Ceiling,
"5.7099684971243493e-62",
"0x1.77d4c76273645E-51#53",
Greater,
);
test(
-1,
200,
53,
Nearest,
"5.7099684971243493e-62",
"0x1.77d4c76273645E-51#53",
Greater,
);
test(
-1,
200,
100,
Nearest,
"5.7099684971243490026437400060191e-62",
"0x1.77d4c76273644a29410f31c68E-51#100",
Less,
);
test(5, 300, 1, Down, "9.8e-91", "0x2.0E-75#1", Less);
test(5, 300, 1, Up, "2.0e-90", "0x4.0E-75#1", Greater);
test(5, 300, 1, Floor, "9.8e-91", "0x2.0E-75#1", Less);
test(5, 300, 1, Ceiling, "2.0e-90", "0x4.0E-75#1", Greater);
test(5, 300, 1, Nearest, "9.8e-91", "0x2.0E-75#1", Less);
test(5, 300, 10, Down, "1.2330e-90", "0x2.83E-75#10", Less);
test(5, 300, 10, Up, "1.2349e-90", "0x2.84E-75#10", Greater);
test(5, 300, 10, Floor, "1.2330e-90", "0x2.83E-75#10", Less);
test(5, 300, 10, Ceiling, "1.2349e-90", "0x2.84E-75#10", Greater);
test(5, 300, 10, Nearest, "1.2330e-90", "0x2.83E-75#10", Less);
test(
5,
300,
53,
Down,
"1.2331064348210500e-90",
"0x2.830ab5bd30106E-75#53",
Less,
);
test(
5,
300,
53,
Up,
"1.2331064348210502e-90",
"0x2.830ab5bd30108E-75#53",
Greater,
);
test(
5,
300,
53,
Floor,
"1.2331064348210500e-90",
"0x2.830ab5bd30106E-75#53",
Less,
);
test(
5,
300,
53,
Ceiling,
"1.2331064348210502e-90",
"0x2.830ab5bd30108E-75#53",
Greater,
);
test(
5,
300,
53,
Nearest,
"1.2331064348210500e-90",
"0x2.830ab5bd30106E-75#53",
Less,
);
test(
5,
300,
100,
Nearest,
"1.2331064348210500019313688799045e-90",
"0x2.830ab5bd3010604469f0fe1b0E-75#100",
Greater,
);
test(-3, 300, 1, Down, "-4.9e-91", "-0x1.0E-75#1", Greater);
test(-3, 300, 1, Up, "-9.8e-91", "-0x2.0E-75#1", Less);
test(-3, 300, 1, Floor, "-9.8e-91", "-0x2.0E-75#1", Less);
test(-3, 300, 1, Ceiling, "-4.9e-91", "-0x1.0E-75#1", Greater);
test(-3, 300, 1, Nearest, "-9.8e-91", "-0x2.0E-75#1", Less);
test(-3, 300, 10, Down, "-7.3924e-91", "-0x1.818E-75#10", Greater);
test(-3, 300, 10, Up, "-7.4020e-91", "-0x1.820E-75#10", Less);
test(-3, 300, 10, Floor, "-7.4020e-91", "-0x1.820E-75#10", Less);
test(
-3,
300,
10,
Ceiling,
"-7.3924e-91",
"-0x1.818E-75#10",
Greater,
);
test(-3, 300, 10, Nearest, "-7.4020e-91", "-0x1.820E-75#10", Less);
test(
-3,
300,
53,
Down,
"-7.3986386089262991e-91",
"-0x1.81d339d7e9a36E-75#53",
Greater,
);
test(
-3,
300,
53,
Up,
"-7.3986386089263002e-91",
"-0x1.81d339d7e9a37E-75#53",
Less,
);
test(
-3,
300,
53,
Floor,
"-7.3986386089263002e-91",
"-0x1.81d339d7e9a37E-75#53",
Less,
);
test(
-3,
300,
53,
Ceiling,
"-7.3986386089262991e-91",
"-0x1.81d339d7e9a36E-75#53",
Greater,
);
test(
-3,
300,
53,
Nearest,
"-7.3986386089263002e-91",
"-0x1.81d339d7e9a37E-75#53",
Less,
);
test(
-3,
300,
100,
Nearest,
"-7.3986386089263000115882132794221e-91",
"-0x1.81d339d7e9a36cf5d92a32102E-75#100",
Greater,
);
test(7, 1000, 1, Down, "-3.7e-301", "-0x4.0E-250#1", Greater);
test(7, 1000, 1, Up, "-7.5e-301", "-0x8.0E-250#1", Less);
test(7, 1000, 1, Floor, "-7.5e-301", "-0x8.0E-250#1", Less);
test(7, 1000, 1, Ceiling, "-3.7e-301", "-0x4.0E-250#1", Greater);
test(7, 1000, 1, Nearest, "-3.7e-301", "-0x4.0E-250#1", Greater);
test(
7,
1000,
10,
Down,
"-4.3747e-301",
"-0x4.b0E-250#10",
Greater,
);
test(7, 1000, 10, Up, "-4.3820e-301", "-0x4.b2E-250#10", Less);
test(7, 1000, 10, Floor, "-4.3820e-301", "-0x4.b2E-250#10", Less);
test(
7,
1000,
10,
Ceiling,
"-4.3747e-301",
"-0x4.b0E-250#10",
Greater,
);
test(
7,
1000,
10,
Nearest,
"-4.3820e-301",
"-0x4.b2E-250#10",
Less,
);
test(
7,
1000,
53,
Down,
"-4.3804042091405903e-301",
"-0x4.b19271bf377b0E-250#53",
Greater,
);
test(
7,
1000,
53,
Up,
"-4.3804042091405911e-301",
"-0x4.b19271bf377b4E-250#53",
Less,
);
test(
7,
1000,
53,
Floor,
"-4.3804042091405911e-301",
"-0x4.b19271bf377b4E-250#53",
Less,
);
test(
7,
1000,
53,
Ceiling,
"-4.3804042091405903e-301",
"-0x4.b19271bf377b0E-250#53",
Greater,
);
test(
7,
1000,
53,
Nearest,
"-4.3804042091405911e-301",
"-0x4.b19271bf377b4E-250#53",
Less,
);
test(
7,
1000,
100,
Nearest,
"-4.3804042091405911132891649396465e-301",
"-0x4.b19271bf377b3dd80357392f8E-250#100",
Greater,
);
test(1, 5000, 1, Down, "-3.5e-1506", "-0x8.0E-1251#1", Greater);
test(1, 5000, 1, Up, "-7.1e-1506", "-0x1.0E-1250#1", Less);
test(1, 5000, 1, Floor, "-7.1e-1506", "-0x1.0E-1250#1", Less);
test(1, 5000, 1, Ceiling, "-3.5e-1506", "-0x8.0E-1251#1", Greater);
test(1, 5000, 1, Nearest, "-3.5e-1506", "-0x8.0E-1251#1", Greater);
test(
1,
5000,
10,
Down,
"-4.8466e-1506",
"-0xa.f4E-1251#10",
Greater,
);
test(1, 5000, 10, Up, "-4.8535e-1506", "-0xa.f8E-1251#10", Less);
test(
1,
5000,
10,
Floor,
"-4.8535e-1506",
"-0xa.f8E-1251#10",
Less,
);
test(
1,
5000,
10,
Ceiling,
"-4.8466e-1506",
"-0xa.f4E-1251#10",
Greater,
);
test(
1,
5000,
10,
Nearest,
"-4.8535e-1506",
"-0xa.f8E-1251#10",
Less,
);
test(
1,
5000,
53,
Down,
"-4.8535006557356868e-1506",
"-0xa.f7f9cdfe9c6c0E-1251#53",
Greater,
);
test(
1,
5000,
53,
Up,
"-4.8535006557356876e-1506",
"-0xa.f7f9cdfe9c6c8E-1251#53",
Less,
);
test(
1,
5000,
53,
Floor,
"-4.8535006557356876e-1506",
"-0xa.f7f9cdfe9c6c8E-1251#53",
Less,
);
test(
1,
5000,
53,
Ceiling,
"-4.8535006557356868e-1506",
"-0xa.f7f9cdfe9c6c0E-1251#53",
Greater,
);
test(
1,
5000,
53,
Nearest,
"-4.8535006557356868e-1506",
"-0xa.f7f9cdfe9c6c0E-1251#53",
Greater,
);
test(
1,
5000,
100,
Nearest,
"-4.8535006557356870949617714368251e-1506",
"-0xa.f7f9cdfe9c6c34c306d00827E-1251#100",
Greater,
);
test(1048577, 1000, 1, Down, "4.9e-296", "0x8.0E-246#1", Less);
test(1048577, 1000, 1, Up, "9.8e-296", "0x1.0E-245#1", Greater);
test(1048577, 1000, 1, Floor, "4.9e-296", "0x8.0E-246#1", Less);
test(
1048577,
1000,
1,
Ceiling,
"9.8e-296",
"0x1.0E-245#1",
Greater,
);
test(1048577, 1000, 1, Nearest, "4.9e-296", "0x8.0E-246#1", Less);
test(
1048577,
1000,
10,
Down,
"6.5558e-296",
"0xa.b8E-246#10",
Less,
);
test(
1048577,
1000,
10,
Up,
"6.5654e-296",
"0xa.bcE-246#10",
Greater,
);
test(
1048577,
1000,
10,
Floor,
"6.5558e-296",
"0xa.b8E-246#10",
Less,
);
test(
1048577,
1000,
10,
Ceiling,
"6.5654e-296",
"0xa.bcE-246#10",
Greater,
);
test(
1048577,
1000,
10,
Nearest,
"6.5654e-296",
"0xa.bcE-246#10",
Greater,
);
test(
1048577,
1000,
53,
Down,
"6.5617015777257331e-296",
"0xa.ba73f8c9fcc70E-246#53",
Less,
);
test(
1048577,
1000,
53,
Up,
"6.5617015777257342e-296",
"0xa.ba73f8c9fcc78E-246#53",
Greater,
);
test(
1048577,
1000,
53,
Floor,
"6.5617015777257331e-296",
"0xa.ba73f8c9fcc70E-246#53",
Less,
);
test(
1048577,
1000,
53,
Ceiling,
"6.5617015777257342e-296",
"0xa.ba73f8c9fcc78E-246#53",
Greater,
);
test(
1048577,
1000,
53,
Nearest,
"6.5617015777257342e-296",
"0xa.ba73f8c9fcc78E-246#53",
Greater,
);
test(
1048577,
1000,
100,
Nearest,
"6.5617015777257337254277324355972e-296",
"0xa.ba73f8c9fcc74c23ebe63a0bE-246#100",
Less,
);
test(
1048579,
2000,
1,
Down,
"-2.3e-597",
"-0x4.0E-496#1",
Greater,
);
test(1048579, 2000, 1, Up, "-4.6e-597", "-0x8.0E-496#1", Less);
test(1048579, 2000, 1, Floor, "-4.6e-597", "-0x8.0E-496#1", Less);
test(
1048579,
2000,
1,
Ceiling,
"-2.3e-597",
"-0x4.0E-496#1",
Greater,
);
test(
1048579,
2000,
1,
Nearest,
"-2.3e-597",
"-0x4.0E-496#1",
Greater,
);
test(
1048579,
2000,
10,
Down,
"-2.3992e-597",
"-0x4.34E-496#10",
Greater,
);
test(
1048579,
2000,
10,
Up,
"-2.4036e-597",
"-0x4.36E-496#10",
Less,
);
test(
1048579,
2000,
10,
Floor,
"-2.4036e-597",
"-0x4.36E-496#10",
Less,
);
test(
1048579,
2000,
10,
Ceiling,
"-2.3992e-597",
"-0x4.34E-496#10",
Greater,
);
test(
1048579,
2000,
10,
Nearest,
"-2.4036e-597",
"-0x4.36E-496#10",
Less,
);
test(
1048579,
2000,
53,
Down,
"-2.4024850074608730e-597",
"-0x4.357cad9e8749cE-496#53",
Greater,
);
test(
1048579,
2000,
53,
Up,
"-2.4024850074608735e-597",
"-0x4.357cad9e874a0E-496#53",
Less,
);
test(
1048579,
2000,
53,
Floor,
"-2.4024850074608735e-597",
"-0x4.357cad9e874a0E-496#53",
Less,
);
test(
1048579,
2000,
53,
Ceiling,
"-2.4024850074608730e-597",
"-0x4.357cad9e8749cE-496#53",
Greater,
);
test(
1048579,
2000,
53,
Nearest,
"-2.4024850074608735e-597",
"-0x4.357cad9e874a0E-496#53",
Less,
);
test(
1048579,
2000,
100,
Nearest,
"-2.4024850074608735037918121034245e-597",
"-0x4.357cad9e8749fdce2e7039980E-496#100",
Less,
);
test(
1,
100,
200,
Nearest,
"8.4784276603688996439587014693867018775520284138208363242266186e-32",
"0x1.b839a252049c1114cf98e804177d4c76273644a29410f31c68E-26#200",
Less,
);
test(
3,
70,
300,
Nearest,
"-9.84601062862050162789118856206421377120257443264456283773667580368778297869791669066481\
56997e-22",
"-0x4.a64f450528ace6f60dd4333e6ecab80c4667247515c03d71a58ba059e79ebdf97f6caad8630E-18#300",
Less,
);
test(
-1,
70,
600,
Nearest,
"3.282003542873500542630396187354737923734191948911604340104315228439512001212817575867967\
731372313070616956744414466712260078477462741735637350786933057556923781236738926841984996\
8371e-22",
"0x1.8cc51701b839a252049c1114cf98e804177cad9cc4d88b22f20ac197d6d5a48d3d31b7c01e756914c1809\
275c428c08a2d0d186e3b4b633dc034a552759a2dcad5da7752b6a6b5ace917c6E-18#600",
Greater,
);
test(
1,
90,
1000,
Nearest,
"2.903855973979360333879556990387591995385154884042586741146238433982103151160615610356893\
779558205091720450596615978798433445783511684248972731919117289147467475007779984454335221\
093892643831504338347538685940013443056453075556384505237755060214145095216776145950987187\
62762754249439112814650591948176017e-28",
"0x1.701b839a252049c1114cf98e804177d4c76273644a294090580192590e69e98ca6b8d595da3bdb8f1b86c\
a16b75da5809b6f06368aafa24eb458c65acd365c322501df79534d51ff0b1be994c00ab59e870160af8a68978\
6d11c4f5de33f2de9ccd39f5e38cf702376a9c68d24864b49903a4060073c54b44eae67107cE-23#1000",
Less,
);
}
#[cfg(not(feature = "32_bit_limbs"))]
#[test]
fn test_cos_underflow() {
let p = (1u64 << 30) + 64;
let min_positive = Float::one_prec(10) >> (1u64 << 30);
assert_eq!(min_positive.get_exponent(), Some(Float::MIN_EXPONENT));
let mut pi = Float::pi_prec_round(p, Floor).0;
let x_lo = &pi >> 1u32;
let (c, o) = x_lo.cos_prec_round_ref(10, Ceiling);
assert_eq!(ComparableFloatRef(&c), ComparableFloatRef(&min_positive));
assert_eq!(o, Greater);
pi.increment();
let x_hi = pi >> 1u32;
let (c, o) = x_hi.cos_prec_round_ref(10, Nearest);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::NEGATIVE_ZERO));
assert_eq!(o, Greater);
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_cos() {
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_cos(x)), NiceFloat(out));
}
test::<f32>(f32::NAN, f32::NAN);
test::<f32>(f32::INFINITY, f32::NAN);
test::<f32>(f32::NEGATIVE_INFINITY, f32::NAN);
test::<f32>(0.0, 1.0);
test::<f32>(-0.0, 1.0);
test::<f32>(1.0, 0.5403023);
test::<f32>(-1.0, 0.5403023);
test::<f32>(0.5, 0.87758255);
test::<f32>(-0.5, 0.87758255);
test::<f32>(2.0, -0.41614684);
test::<f32>(-2.0, -0.41614684);
test::<f32>(core::f32::consts::PI, -1.0);
test::<f32>(core::f32::consts::FRAC_PI_2, -4.371139e-8);
test::<f32>(core::f32::consts::E, -0.91173387);
test::<f32>(100.0, 0.8623189);
test::<f32>(1.0e10, 0.87311965);
test::<f32>(1.0e30, -0.6116048);
test::<f32>(3.4028235e38, 0.853021);
test::<f32>(1.1754944e-38, 1.0);
test::<f64>(f64::NAN, f64::NAN);
test::<f64>(f64::INFINITY, f64::NAN);
test::<f64>(f64::NEGATIVE_INFINITY, f64::NAN);
test::<f64>(0.0, 1.0);
test::<f64>(-0.0, 1.0);
test::<f64>(1.0, 0.5403023058681398);
test::<f64>(-1.0, 0.5403023058681398);
test::<f64>(0.5, 0.8775825618903728);
test::<f64>(-0.5, 0.8775825618903728);
test::<f64>(2.0, -0.4161468365471424);
test::<f64>(-2.0, -0.4161468365471424);
test::<f64>(core::f64::consts::PI, -1.0);
test::<f64>(core::f64::consts::FRAC_PI_2, 6.123233995736766e-17);
test::<f64>(core::f64::consts::E, -0.9117339147869651);
test::<f64>(100.0, 0.8623188722876839);
test::<f64>(1.0e10, 0.873119622676856);
test::<f64>(1.0e100, 0.9247242387519338);
test::<f64>(1.0e300, -0.5753861119575491);
test::<f64>(1.7976931348623157e308, -0.9999876894265599);
test::<f64>(2.2250738585072014e-308, 1.0);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_cos_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_cos(x);
assert_eq!(c.is_nan(), !x.is_finite());
if x.is_finite() {
assert!(c >= T::NEGATIVE_ONE && c <= T::ONE);
assert_eq!(NiceFloat(primitive_float_cos(-x)), NiceFloat(c));
let rug_x = rug::Float::with_val(
u32::exact_from(T::MANTISSA_WIDTH + 1),
&rug::Float::exact_from(&Float::from(x)),
);
let rug_c: T = T::exact_from(&<Float as From<&rug::Float>>::from(&rug_x.cos()));
assert_eq!(NiceFloat(rug_c), NiceFloat(c));
}
});
}
#[test]
fn primitive_float_cos_properties() {
apply_fn_to_primitive_floats!(primitive_float_cos_properties_helper);
}
#[test]
fn test_cos_rational_prec() {
let test = |s, prec, out: &str, out_hex: &str, out_o| {
let x = Rational::from_str(s).unwrap();
let (c, o) = Float::cos_rational_prec(x.clone(), prec);
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::cos_rational_prec_ref(&x, prec);
assert!(c.is_valid());
assert_eq!(c.to_string(), out);
assert_eq!(to_hex_string(&c), out_hex);
assert_eq!(o, out_o);
};
test("0", 1, "1.0", "0x1.0#1", Equal);
test("0", 5, "1.00", "0x1.0#5", Equal);
test("0", 10, "1.0000", "0x1.000#10", Equal);
test("0", 20, "1.0000000", "0x1.00000#20", Equal);
test("0", 53, "1.0000000000000000", "0x1.0000000000000#53", Equal);
test(
"0",
100,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Equal,
);
test("1", 1, "0.50", "0x0.8#1", Less);
test("1", 5, "0.531", "0x0.88#5", Less);
test("1", 10, "0.54004", "0x0.8a4#10", Less);
test("1", 20, "0.54030228", "0x0.8a514#20", Less);
test(
"1",
53,
"0.54030230586813977",
"0x0.8a51407da83460#53",
Greater,
);
test(
"1",
100,
"0.54030230586813971740093660744335",
"0x0.8a51407da8345c91c2466d977#100",
Greater,
);
test("-1", 1, "0.50", "0x0.8#1", Less);
test("-1", 5, "0.531", "0x0.88#5", Less);
test("-1", 10, "0.54004", "0x0.8a4#10", Less);
test("-1", 20, "0.54030228", "0x0.8a514#20", Less);
test(
"-1",
53,
"0.54030230586813977",
"0x0.8a51407da83460#53",
Greater,
);
test(
"-1",
100,
"0.54030230586813971740093660744335",
"0x0.8a51407da8345c91c2466d977#100",
Greater,
);
test("1/2", 1, "1.0", "0x1.0#1", Greater);
test("1/2", 5, "0.875", "0x0.e0#5", Less);
test("1/2", 10, "0.87793", "0x0.e0c#10", Greater);
test("1/2", 20, "0.87758255", "0x0.e0a94#20", Less);
test(
"1/2",
53,
"0.87758256189037276",
"0x0.e0a94032dbea80#53",
Greater,
);
test(
"1/2",
100,
"0.87758256189037271611628158260408",
"0x0.e0a94032dbea7cedbddd9da30#100",
Greater,
);
test("1/3", 1, "1.0", "0x1.0#1", Greater);
test("1/3", 5, "0.938", "0x0.f0#5", Less);
test("1/3", 10, "0.94531", "0x0.f20#10", Greater);
test("1/3", 20, "0.94495678", "0x0.f1e8b#20", Less);
test(
"1/3",
53,
"0.94495694631473770",
"0x0.f1e8b2cc8cc168#53",
Greater,
);
test(
"1/3",
100,
"0.94495694631473766438828400767583",
"0x0.f1e8b2cc8cc1656b6998d964d#100",
Less,
);
test("-1/3", 1, "1.0", "0x1.0#1", Greater);
test("-1/3", 5, "0.938", "0x0.f0#5", Less);
test("-1/3", 10, "0.94531", "0x0.f20#10", Greater);
test("-1/3", 20, "0.94495678", "0x0.f1e8b#20", Less);
test(
"-1/3",
53,
"0.94495694631473770",
"0x0.f1e8b2cc8cc168#53",
Greater,
);
test(
"-1/3",
100,
"0.94495694631473766438828400767583",
"0x0.f1e8b2cc8cc1656b6998d964d#100",
Less,
);
test("3/5", 1, "1.0", "0x1.0#1", Greater);
test("3/5", 10, "0.82520", "0x0.d34#10", Less);
test(
"3/5",
53,
"0.82533561490967833",
"0x0.d34931e242d8a8#53",
Greater,
);
test(
"3/5",
100,
"0.82533561490967829724095249895546",
"0x0.d34931e242d8a5cb448dccbdf#100",
Greater,
);
test("22/7", 1, "-1.0", "-0x1.0#1", Less);
test("22/7", 5, "-1.00", "-0x1.0#5", Less);
test("22/7", 10, "-1.0000", "-0x1.000#10", Less);
test("22/7", 20, "-0.99999905", "-0x0.fffff#20", Greater);
test(
"22/7",
53,
"-0.99999920053355296",
"-0x0.fffff296515870#53",
Less,
);
test(
"22/7",
100,
"-0.99999920053355290326833573965634",
"-0x0.fffff29651586c28bc01f9fb2#100",
Greater,
);
test("-22/7", 1, "-1.0", "-0x1.0#1", Less);
test("-22/7", 5, "-1.00", "-0x1.0#5", Less);
test("-22/7", 10, "-1.0000", "-0x1.000#10", Less);
test("-22/7", 20, "-0.99999905", "-0x0.fffff#20", Greater);
test(
"-22/7",
53,
"-0.99999920053355296",
"-0x0.fffff296515870#53",
Less,
);
test(
"-22/7",
100,
"-0.99999920053355290326833573965634",
"-0x0.fffff29651586c28bc01f9fb2#100",
Greater,
);
test("355/113", 1, "-1.0", "-0x1.0#1", Less);
test("355/113", 5, "-1.00", "-0x1.0#5", Less);
test("355/113", 10, "-1.0000", "-0x1.000#10", Less);
test("355/113", 20, "-1.0000000", "-0x1.00000#20", Less);
test(
"355/113",
53,
"-0.99999999999996447",
"-0x0.fffffffffff600#53",
Less,
);
test(
"355/113",
100,
"-0.99999999999996441843371693431264",
"-0x0.fffffffffff5fc13f3fa12934#100",
Greater,
);
test("3", 1, "-1.0", "-0x1.0#1", Less);
test("3", 5, "-1.00", "-0x1.0#5", Less);
test("3", 10, "-0.99023", "-0x0.fd8#10", Less);
test("3", 20, "-0.98999214", "-0x0.fd702#20", Greater);
test(
"3",
53,
"-0.98999249660044542",
"-0x0.fd7025f42f2e90#53",
Greater,
);
test(
"3",
100,
"-0.98999249660044545727157279473154",
"-0x0.fd7025f42f2e9307dff82fdf7#100",
Less,
);
test("100", 1, "1.0", "0x1.0#1", Greater);
test("100", 5, "0.875", "0x0.e0#5", Greater);
test("100", 10, "0.86230", "0x0.dcc#10", Less);
test("100", 20, "0.86231899", "0x0.dcc0f#20", Greater);
test(
"100",
53,
"0.86231887228768389",
"0x0.dcc0edfb32fef8#53",
Less,
);
test(
"100",
100,
"0.86231887228768393410193851395099",
"0x0.dcc0edfb32fefb1fa19b9b30c#100",
Greater,
);
test("1000000", 1, "1.0", "0x1.0#1", Greater);
test("1000000", 5, "0.938", "0x0.f0#5", Greater);
test("1000000", 10, "0.93652", "0x0.efc#10", Less);
test("1000000", 20, "0.93675232", "0x0.efcf0#20", Greater);
test(
"1000000",
53,
"0.93675212753314474",
"0x0.efcefcc8369960#53",
Less,
);
test(
"1000000",
100,
"0.93675212753314478693853253507492",
"0x0.efcefcc836996357644d418cd#100",
Greater,
);
test("1/1000000", 1, "1.0", "0x1.0#1", Greater);
test("1/1000000", 5, "1.00", "0x1.0#5", Greater);
test("1/1000000", 10, "1.0000", "0x1.000#10", Greater);
test("1/1000000", 20, "1.0000000", "0x1.00000#20", Greater);
test(
"1/1000000",
53,
"0.99999999999949996",
"0x0.ffffffffff7340#53",
Less,
);
test(
"1/1000000",
100,
"0.99999999999950000000000004166665",
"0x0.ffffffffff734333f690bc5c6#100",
Less,
);
test("-1/1000000", 1, "1.0", "0x1.0#1", Greater);
test("-1/1000000", 5, "1.00", "0x1.0#5", Greater);
test("-1/1000000", 10, "1.0000", "0x1.000#10", Greater);
test("-1/1000000", 20, "1.0000000", "0x1.00000#20", Greater);
test(
"-1/1000000",
53,
"0.99999999999949996",
"0x0.ffffffffff7340#53",
Less,
);
test(
"-1/1000000",
100,
"0.99999999999950000000000004166665",
"0x0.ffffffffff734333f690bc5c6#100",
Less,
);
test("1/1000000000000000000000000", 1, "1.0", "0x1.0#1", Greater);
test("1/1000000000000000000000000", 5, "1.00", "0x1.0#5", Greater);
test(
"1/1000000000000000000000000",
10,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1000000000000000000000000",
20,
"1.0000000",
"0x1.00000#20",
Greater,
);
test(
"1/1000000000000000000000000",
53,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1/1000000000000000000000000",
100,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
1,
"9.9e-32",
"0x2.0E-26#1",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
5,
"8.63e-32",
"0x1.cE-26#5",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
10,
"8.4741e-32",
"0x1.b80E-26#10",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
20,
"8.4784270e-32",
"0x1.b839aE-26#20",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
53,
"8.4784276603688996e-32",
"0x1.b839a252049c1E-26#53",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
100,
"8.4784276603688996439587014693888e-32",
"0x1.b839a252049c1114cf98e8042E-26#100",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
1,
"-2.0e-31",
"-0x4.0E-26#1",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
5,
"-2.59e-31",
"-0x5.4E-26#5",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
10,
"-2.5422e-31",
"-0x5.28E-26#10",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
20,
"-2.5435290e-31",
"-0x5.28ad0E-26#20",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
53,
"-2.5435282981106700e-31",
"-0x5.28ace6f60dd44E-26#53",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
100,
"-2.5435282981106698931876104408174e-31",
"-0x5.28ace6f60dd4333e6ecab80c8E-26#100",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
1,
"-1.0",
"-0x1.0#1",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
5,
"-1.00",
"-0x1.0#5",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
10,
"-1.0000",
"-0x1.000#10",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
20,
"-1.0000000",
"-0x1.00000#20",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
53,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
100,
"-1.0000000000000000000000000000000",
"-0x1.0000000000000000000000000#100",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
1,
"9.9e-32",
"0x2.0E-26#1",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
5,
"8.63e-32",
"0x1.cE-26#5",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
10,
"8.4741e-32",
"0x1.b80E-26#10",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
20,
"8.4784270e-32",
"0x1.b839aE-26#20",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
53,
"8.4784276603688996e-32",
"0x1.b839a252049c1E-26#53",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
100,
"8.4784276603688996439587014693888e-32",
"0x1.b839a252049c1114cf98e8042E-26#100",
Greater,
);
test(
"1267650600228229401496703205376",
1,
"0.50",
"0x0.8#1",
Greater,
);
test(
"1267650600228229401496703205376",
5,
"0.484",
"0x0.7c#5",
Less,
);
test(
"1267650600228229401496703205376",
10,
"0.48926",
"0x0.7d4#10",
Greater,
);
test(
"1267650600228229401496703205376",
20,
"0.48917866",
"0x0.7d3ad0#20",
Greater,
);
test(
"1267650600228229401496703205376",
53,
"0.48917865697472146",
"0x0.7d3acffd9b8db4#53",
Greater,
);
test(
"1267650600228229401496703205376",
100,
"0.48917865697472144990578930875139",
"0x0.7d3acffd9b8db34b71d86c7ff0#100",
Greater,
);
test(
"1/1267650600228229401496703205376",
1,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/1267650600228229401496703205376",
5,
"1.00",
"0x1.0#5",
Greater,
);
test(
"1/1267650600228229401496703205376",
10,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1267650600228229401496703205376",
20,
"1.0000000",
"0x1.00000#20",
Greater,
);
test(
"1/1267650600228229401496703205376",
53,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1/1267650600228229401496703205376",
100,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
}
#[test]
fn test_cos_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::cos_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::cos_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);
};
test("0", 1, Down, "1.0", "0x1.0#1", Equal);
test("0", 1, Up, "1.0", "0x1.0#1", Equal);
test("0", 1, Floor, "1.0", "0x1.0#1", Equal);
test("0", 1, Ceiling, "1.0", "0x1.0#1", Equal);
test("0", 1, Nearest, "1.0", "0x1.0#1", Equal);
test("0", 1, Exact, "1.0", "0x1.0#1", Equal);
test("0", 5, Nearest, "1.00", "0x1.0#5", Equal);
test("0", 10, Down, "1.0000", "0x1.000#10", Equal);
test("0", 10, Up, "1.0000", "0x1.000#10", Equal);
test("0", 10, Floor, "1.0000", "0x1.000#10", Equal);
test("0", 10, Ceiling, "1.0000", "0x1.000#10", Equal);
test("0", 10, Nearest, "1.0000", "0x1.000#10", Equal);
test("0", 10, Exact, "1.0000", "0x1.000#10", Equal);
test("0", 20, Nearest, "1.0000000", "0x1.00000#20", Equal);
test(
"0",
53,
Down,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"0",
53,
Up,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"0",
53,
Floor,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"0",
53,
Ceiling,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"0",
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"0",
53,
Exact,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"0",
100,
Nearest,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Equal,
);
test("1", 1, Down, "0.50", "0x0.8#1", Less);
test("1", 1, Up, "1.0", "0x1.0#1", Greater);
test("1", 1, Floor, "0.50", "0x0.8#1", Less);
test("1", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("1", 1, Nearest, "0.50", "0x0.8#1", Less);
test("1", 5, Nearest, "0.531", "0x0.88#5", Less);
test("1", 10, Down, "0.54004", "0x0.8a4#10", Less);
test("1", 10, Up, "0.54102", "0x0.8a8#10", Greater);
test("1", 10, Floor, "0.54004", "0x0.8a4#10", Less);
test("1", 10, Ceiling, "0.54102", "0x0.8a8#10", Greater);
test("1", 10, Nearest, "0.54004", "0x0.8a4#10", Less);
test("1", 20, Nearest, "0.54030228", "0x0.8a514#20", Less);
test(
"1",
53,
Down,
"0.54030230586813965",
"0x0.8a51407da83458#53",
Less,
);
test(
"1",
53,
Up,
"0.54030230586813977",
"0x0.8a51407da83460#53",
Greater,
);
test(
"1",
53,
Floor,
"0.54030230586813965",
"0x0.8a51407da83458#53",
Less,
);
test(
"1",
53,
Ceiling,
"0.54030230586813977",
"0x0.8a51407da83460#53",
Greater,
);
test(
"1",
53,
Nearest,
"0.54030230586813977",
"0x0.8a51407da83460#53",
Greater,
);
test(
"1",
100,
Nearest,
"0.54030230586813971740093660744335",
"0x0.8a51407da8345c91c2466d977#100",
Greater,
);
test("-1", 1, Down, "0.50", "0x0.8#1", Less);
test("-1", 1, Up, "1.0", "0x1.0#1", Greater);
test("-1", 1, Floor, "0.50", "0x0.8#1", Less);
test("-1", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("-1", 1, Nearest, "0.50", "0x0.8#1", Less);
test("-1", 5, Nearest, "0.531", "0x0.88#5", Less);
test("-1", 10, Down, "0.54004", "0x0.8a4#10", Less);
test("-1", 10, Up, "0.54102", "0x0.8a8#10", Greater);
test("-1", 10, Floor, "0.54004", "0x0.8a4#10", Less);
test("-1", 10, Ceiling, "0.54102", "0x0.8a8#10", Greater);
test("-1", 10, Nearest, "0.54004", "0x0.8a4#10", Less);
test("-1", 20, Nearest, "0.54030228", "0x0.8a514#20", Less);
test(
"-1",
53,
Down,
"0.54030230586813965",
"0x0.8a51407da83458#53",
Less,
);
test(
"-1",
53,
Up,
"0.54030230586813977",
"0x0.8a51407da83460#53",
Greater,
);
test(
"-1",
53,
Floor,
"0.54030230586813965",
"0x0.8a51407da83458#53",
Less,
);
test(
"-1",
53,
Ceiling,
"0.54030230586813977",
"0x0.8a51407da83460#53",
Greater,
);
test(
"-1",
53,
Nearest,
"0.54030230586813977",
"0x0.8a51407da83460#53",
Greater,
);
test(
"-1",
100,
Nearest,
"0.54030230586813971740093660744335",
"0x0.8a51407da8345c91c2466d977#100",
Greater,
);
test("1/2", 1, Down, "0.50", "0x0.8#1", Less);
test("1/2", 1, Up, "1.0", "0x1.0#1", Greater);
test("1/2", 1, Floor, "0.50", "0x0.8#1", Less);
test("1/2", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("1/2", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1/2", 5, Nearest, "0.875", "0x0.e0#5", Less);
test("1/2", 10, Down, "0.87695", "0x0.e08#10", Less);
test("1/2", 10, Up, "0.87793", "0x0.e0c#10", Greater);
test("1/2", 10, Floor, "0.87695", "0x0.e08#10", Less);
test("1/2", 10, Ceiling, "0.87793", "0x0.e0c#10", Greater);
test("1/2", 10, Nearest, "0.87793", "0x0.e0c#10", Greater);
test("1/2", 20, Nearest, "0.87758255", "0x0.e0a94#20", Less);
test(
"1/2",
53,
Down,
"0.87758256189037265",
"0x0.e0a94032dbea78#53",
Less,
);
test(
"1/2",
53,
Up,
"0.87758256189037276",
"0x0.e0a94032dbea80#53",
Greater,
);
test(
"1/2",
53,
Floor,
"0.87758256189037265",
"0x0.e0a94032dbea78#53",
Less,
);
test(
"1/2",
53,
Ceiling,
"0.87758256189037276",
"0x0.e0a94032dbea80#53",
Greater,
);
test(
"1/2",
53,
Nearest,
"0.87758256189037276",
"0x0.e0a94032dbea80#53",
Greater,
);
test(
"1/2",
100,
Nearest,
"0.87758256189037271611628158260408",
"0x0.e0a94032dbea7cedbddd9da30#100",
Greater,
);
test("1/3", 1, Down, "0.50", "0x0.8#1", Less);
test("1/3", 1, Up, "1.0", "0x1.0#1", 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", 5, Nearest, "0.938", "0x0.f0#5", Less);
test("1/3", 10, Down, "0.94434", "0x0.f1c#10", Less);
test("1/3", 10, Up, "0.94531", "0x0.f20#10", Greater);
test("1/3", 10, Floor, "0.94434", "0x0.f1c#10", Less);
test("1/3", 10, Ceiling, "0.94531", "0x0.f20#10", Greater);
test("1/3", 10, Nearest, "0.94531", "0x0.f20#10", Greater);
test("1/3", 20, Nearest, "0.94495678", "0x0.f1e8b#20", Less);
test(
"1/3",
53,
Down,
"0.94495694631473759",
"0x0.f1e8b2cc8cc160#53",
Less,
);
test(
"1/3",
53,
Up,
"0.94495694631473770",
"0x0.f1e8b2cc8cc168#53",
Greater,
);
test(
"1/3",
53,
Floor,
"0.94495694631473759",
"0x0.f1e8b2cc8cc160#53",
Less,
);
test(
"1/3",
53,
Ceiling,
"0.94495694631473770",
"0x0.f1e8b2cc8cc168#53",
Greater,
);
test(
"1/3",
53,
Nearest,
"0.94495694631473770",
"0x0.f1e8b2cc8cc168#53",
Greater,
);
test(
"1/3",
100,
Nearest,
"0.94495694631473766438828400767583",
"0x0.f1e8b2cc8cc1656b6998d964d#100",
Less,
);
test("-1/3", 1, Down, "0.50", "0x0.8#1", Less);
test("-1/3", 1, Up, "1.0", "0x1.0#1", 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", 5, Nearest, "0.938", "0x0.f0#5", Less);
test("-1/3", 10, Down, "0.94434", "0x0.f1c#10", Less);
test("-1/3", 10, Up, "0.94531", "0x0.f20#10", Greater);
test("-1/3", 10, Floor, "0.94434", "0x0.f1c#10", Less);
test("-1/3", 10, Ceiling, "0.94531", "0x0.f20#10", Greater);
test("-1/3", 10, Nearest, "0.94531", "0x0.f20#10", Greater);
test("-1/3", 20, Nearest, "0.94495678", "0x0.f1e8b#20", Less);
test(
"-1/3",
53,
Down,
"0.94495694631473759",
"0x0.f1e8b2cc8cc160#53",
Less,
);
test(
"-1/3",
53,
Up,
"0.94495694631473770",
"0x0.f1e8b2cc8cc168#53",
Greater,
);
test(
"-1/3",
53,
Floor,
"0.94495694631473759",
"0x0.f1e8b2cc8cc160#53",
Less,
);
test(
"-1/3",
53,
Ceiling,
"0.94495694631473770",
"0x0.f1e8b2cc8cc168#53",
Greater,
);
test(
"-1/3",
53,
Nearest,
"0.94495694631473770",
"0x0.f1e8b2cc8cc168#53",
Greater,
);
test(
"-1/3",
100,
Nearest,
"0.94495694631473766438828400767583",
"0x0.f1e8b2cc8cc1656b6998d964d#100",
Less,
);
test("3/5", 1, Down, "0.50", "0x0.8#1", Less);
test("3/5", 1, Up, "1.0", "0x1.0#1", 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, Down, "0.82520", "0x0.d34#10", Less);
test("3/5", 10, Up, "0.82617", "0x0.d38#10", Greater);
test("3/5", 10, Floor, "0.82520", "0x0.d34#10", Less);
test("3/5", 10, Ceiling, "0.82617", "0x0.d38#10", Greater);
test("3/5", 10, Nearest, "0.82520", "0x0.d34#10", Less);
test(
"3/5",
53,
Down,
"0.82533561490967822",
"0x0.d34931e242d8a0#53",
Less,
);
test(
"3/5",
53,
Up,
"0.82533561490967833",
"0x0.d34931e242d8a8#53",
Greater,
);
test(
"3/5",
53,
Floor,
"0.82533561490967822",
"0x0.d34931e242d8a0#53",
Less,
);
test(
"3/5",
53,
Ceiling,
"0.82533561490967833",
"0x0.d34931e242d8a8#53",
Greater,
);
test(
"3/5",
53,
Nearest,
"0.82533561490967833",
"0x0.d34931e242d8a8#53",
Greater,
);
test(
"3/5",
100,
Nearest,
"0.82533561490967829724095249895546",
"0x0.d34931e242d8a5cb448dccbdf#100",
Greater,
);
test("22/7", 1, Down, "-0.50", "-0x0.8#1", Greater);
test("22/7", 1, Up, "-1.0", "-0x1.0#1", Less);
test("22/7", 1, Floor, "-1.0", "-0x1.0#1", Less);
test("22/7", 1, Ceiling, "-0.50", "-0x0.8#1", Greater);
test("22/7", 1, Nearest, "-1.0", "-0x1.0#1", Less);
test("22/7", 5, Nearest, "-1.00", "-0x1.0#5", Less);
test("22/7", 10, Down, "-0.99902", "-0x0.ffc#10", Greater);
test("22/7", 10, Up, "-1.0000", "-0x1.000#10", Less);
test("22/7", 10, Floor, "-1.0000", "-0x1.000#10", Less);
test("22/7", 10, Ceiling, "-0.99902", "-0x0.ffc#10", Greater);
test("22/7", 10, Nearest, "-1.0000", "-0x1.000#10", Less);
test("22/7", 20, Nearest, "-0.99999905", "-0x0.fffff#20", Greater);
test(
"22/7",
53,
Down,
"-0.99999920053355285",
"-0x0.fffff296515868#53",
Greater,
);
test(
"22/7",
53,
Up,
"-0.99999920053355296",
"-0x0.fffff296515870#53",
Less,
);
test(
"22/7",
53,
Floor,
"-0.99999920053355296",
"-0x0.fffff296515870#53",
Less,
);
test(
"22/7",
53,
Ceiling,
"-0.99999920053355285",
"-0x0.fffff296515868#53",
Greater,
);
test(
"22/7",
53,
Nearest,
"-0.99999920053355296",
"-0x0.fffff296515870#53",
Less,
);
test(
"22/7",
100,
Nearest,
"-0.99999920053355290326833573965634",
"-0x0.fffff29651586c28bc01f9fb2#100",
Greater,
);
test("-22/7", 1, Down, "-0.50", "-0x0.8#1", Greater);
test("-22/7", 1, Up, "-1.0", "-0x1.0#1", Less);
test("-22/7", 1, Floor, "-1.0", "-0x1.0#1", Less);
test("-22/7", 1, Ceiling, "-0.50", "-0x0.8#1", Greater);
test("-22/7", 1, Nearest, "-1.0", "-0x1.0#1", Less);
test("-22/7", 5, Nearest, "-1.00", "-0x1.0#5", Less);
test("-22/7", 10, Down, "-0.99902", "-0x0.ffc#10", Greater);
test("-22/7", 10, Up, "-1.0000", "-0x1.000#10", Less);
test("-22/7", 10, Floor, "-1.0000", "-0x1.000#10", Less);
test("-22/7", 10, Ceiling, "-0.99902", "-0x0.ffc#10", Greater);
test("-22/7", 10, Nearest, "-1.0000", "-0x1.000#10", Less);
test(
"-22/7",
20,
Nearest,
"-0.99999905",
"-0x0.fffff#20",
Greater,
);
test(
"-22/7",
53,
Down,
"-0.99999920053355285",
"-0x0.fffff296515868#53",
Greater,
);
test(
"-22/7",
53,
Up,
"-0.99999920053355296",
"-0x0.fffff296515870#53",
Less,
);
test(
"-22/7",
53,
Floor,
"-0.99999920053355296",
"-0x0.fffff296515870#53",
Less,
);
test(
"-22/7",
53,
Ceiling,
"-0.99999920053355285",
"-0x0.fffff296515868#53",
Greater,
);
test(
"-22/7",
53,
Nearest,
"-0.99999920053355296",
"-0x0.fffff296515870#53",
Less,
);
test(
"-22/7",
100,
Nearest,
"-0.99999920053355290326833573965634",
"-0x0.fffff29651586c28bc01f9fb2#100",
Greater,
);
test("355/113", 1, Down, "-0.50", "-0x0.8#1", Greater);
test("355/113", 1, Up, "-1.0", "-0x1.0#1", Less);
test("355/113", 1, Floor, "-1.0", "-0x1.0#1", Less);
test("355/113", 1, Ceiling, "-0.50", "-0x0.8#1", Greater);
test("355/113", 1, Nearest, "-1.0", "-0x1.0#1", Less);
test("355/113", 5, Nearest, "-1.00", "-0x1.0#5", Less);
test("355/113", 10, Down, "-0.99902", "-0x0.ffc#10", Greater);
test("355/113", 10, Up, "-1.0000", "-0x1.000#10", Less);
test("355/113", 10, Floor, "-1.0000", "-0x1.000#10", Less);
test("355/113", 10, Ceiling, "-0.99902", "-0x0.ffc#10", Greater);
test("355/113", 10, Nearest, "-1.0000", "-0x1.000#10", Less);
test("355/113", 20, Nearest, "-1.0000000", "-0x1.00000#20", Less);
test(
"355/113",
53,
Down,
"-0.99999999999996436",
"-0x0.fffffffffff5f8#53",
Greater,
);
test(
"355/113",
53,
Up,
"-0.99999999999996447",
"-0x0.fffffffffff600#53",
Less,
);
test(
"355/113",
53,
Floor,
"-0.99999999999996447",
"-0x0.fffffffffff600#53",
Less,
);
test(
"355/113",
53,
Ceiling,
"-0.99999999999996436",
"-0x0.fffffffffff5f8#53",
Greater,
);
test(
"355/113",
53,
Nearest,
"-0.99999999999996447",
"-0x0.fffffffffff600#53",
Less,
);
test(
"355/113",
100,
Nearest,
"-0.99999999999996441843371693431264",
"-0x0.fffffffffff5fc13f3fa12934#100",
Greater,
);
test("3", 1, Down, "-0.50", "-0x0.8#1", Greater);
test("3", 1, Up, "-1.0", "-0x1.0#1", Less);
test("3", 1, Floor, "-1.0", "-0x1.0#1", Less);
test("3", 1, Ceiling, "-0.50", "-0x0.8#1", Greater);
test("3", 1, Nearest, "-1.0", "-0x1.0#1", Less);
test("3", 5, Nearest, "-1.00", "-0x1.0#5", Less);
test("3", 10, Down, "-0.98926", "-0x0.fd4#10", Greater);
test("3", 10, Up, "-0.99023", "-0x0.fd8#10", Less);
test("3", 10, Floor, "-0.99023", "-0x0.fd8#10", Less);
test("3", 10, Ceiling, "-0.98926", "-0x0.fd4#10", Greater);
test("3", 10, Nearest, "-0.99023", "-0x0.fd8#10", Less);
test("3", 20, Nearest, "-0.98999214", "-0x0.fd702#20", Greater);
test(
"3",
53,
Down,
"-0.98999249660044542",
"-0x0.fd7025f42f2e90#53",
Greater,
);
test(
"3",
53,
Up,
"-0.98999249660044553",
"-0x0.fd7025f42f2e98#53",
Less,
);
test(
"3",
53,
Floor,
"-0.98999249660044553",
"-0x0.fd7025f42f2e98#53",
Less,
);
test(
"3",
53,
Ceiling,
"-0.98999249660044542",
"-0x0.fd7025f42f2e90#53",
Greater,
);
test(
"3",
53,
Nearest,
"-0.98999249660044542",
"-0x0.fd7025f42f2e90#53",
Greater,
);
test(
"3",
100,
Nearest,
"-0.98999249660044545727157279473154",
"-0x0.fd7025f42f2e9307dff82fdf7#100",
Less,
);
test("100", 1, Down, "0.50", "0x0.8#1", Less);
test("100", 1, Up, "1.0", "0x1.0#1", Greater);
test("100", 1, Floor, "0.50", "0x0.8#1", Less);
test("100", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("100", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("100", 5, Nearest, "0.875", "0x0.e0#5", Greater);
test("100", 10, Down, "0.86230", "0x0.dcc#10", Less);
test("100", 10, Up, "0.86328", "0x0.dd0#10", Greater);
test("100", 10, Floor, "0.86230", "0x0.dcc#10", Less);
test("100", 10, Ceiling, "0.86328", "0x0.dd0#10", Greater);
test("100", 10, Nearest, "0.86230", "0x0.dcc#10", Less);
test("100", 20, Nearest, "0.86231899", "0x0.dcc0f#20", Greater);
test(
"100",
53,
Down,
"0.86231887228768389",
"0x0.dcc0edfb32fef8#53",
Less,
);
test(
"100",
53,
Up,
"0.86231887228768400",
"0x0.dcc0edfb32ff00#53",
Greater,
);
test(
"100",
53,
Floor,
"0.86231887228768389",
"0x0.dcc0edfb32fef8#53",
Less,
);
test(
"100",
53,
Ceiling,
"0.86231887228768400",
"0x0.dcc0edfb32ff00#53",
Greater,
);
test(
"100",
53,
Nearest,
"0.86231887228768389",
"0x0.dcc0edfb32fef8#53",
Less,
);
test(
"100",
100,
Nearest,
"0.86231887228768393410193851395099",
"0x0.dcc0edfb32fefb1fa19b9b30c#100",
Greater,
);
test("1000000", 1, Down, "0.50", "0x0.8#1", Less);
test("1000000", 1, Up, "1.0", "0x1.0#1", Greater);
test("1000000", 1, Floor, "0.50", "0x0.8#1", Less);
test("1000000", 1, Ceiling, "1.0", "0x1.0#1", Greater);
test("1000000", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1000000", 5, Nearest, "0.938", "0x0.f0#5", Greater);
test("1000000", 10, Down, "0.93652", "0x0.efc#10", Less);
test("1000000", 10, Up, "0.93750", "0x0.f00#10", Greater);
test("1000000", 10, Floor, "0.93652", "0x0.efc#10", Less);
test("1000000", 10, Ceiling, "0.93750", "0x0.f00#10", Greater);
test("1000000", 10, Nearest, "0.93652", "0x0.efc#10", Less);
test(
"1000000",
20,
Nearest,
"0.93675232",
"0x0.efcf0#20",
Greater,
);
test(
"1000000",
53,
Down,
"0.93675212753314474",
"0x0.efcefcc8369960#53",
Less,
);
test(
"1000000",
53,
Up,
"0.93675212753314485",
"0x0.efcefcc8369968#53",
Greater,
);
test(
"1000000",
53,
Floor,
"0.93675212753314474",
"0x0.efcefcc8369960#53",
Less,
);
test(
"1000000",
53,
Ceiling,
"0.93675212753314485",
"0x0.efcefcc8369968#53",
Greater,
);
test(
"1000000",
53,
Nearest,
"0.93675212753314474",
"0x0.efcefcc8369960#53",
Less,
);
test(
"1000000",
100,
Nearest,
"0.93675212753314478693853253507492",
"0x0.efcefcc836996357644d418cd#100",
Greater,
);
test("1/1000000", 1, Down, "0.50", "0x0.8#1", Less);
test("1/1000000", 1, Up, "1.0", "0x1.0#1", 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", 5, Nearest, "1.00", "0x1.0#5", Greater);
test("1/1000000", 10, Down, "0.99902", "0x0.ffc#10", Less);
test("1/1000000", 10, Up, "1.0000", "0x1.000#10", 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",
20,
Nearest,
"1.0000000",
"0x1.00000#20",
Greater,
);
test(
"1/1000000",
53,
Down,
"0.99999999999949996",
"0x0.ffffffffff7340#53",
Less,
);
test(
"1/1000000",
53,
Up,
"0.99999999999950007",
"0x0.ffffffffff7348#53",
Greater,
);
test(
"1/1000000",
53,
Floor,
"0.99999999999949996",
"0x0.ffffffffff7340#53",
Less,
);
test(
"1/1000000",
53,
Ceiling,
"0.99999999999950007",
"0x0.ffffffffff7348#53",
Greater,
);
test(
"1/1000000",
53,
Nearest,
"0.99999999999949996",
"0x0.ffffffffff7340#53",
Less,
);
test(
"1/1000000",
100,
Nearest,
"0.99999999999950000000000004166665",
"0x0.ffffffffff734333f690bc5c6#100",
Less,
);
test("-1/1000000", 1, Down, "0.50", "0x0.8#1", Less);
test("-1/1000000", 1, Up, "1.0", "0x1.0#1", 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", 5, Nearest, "1.00", "0x1.0#5", Greater);
test("-1/1000000", 10, Down, "0.99902", "0x0.ffc#10", Less);
test("-1/1000000", 10, Up, "1.0000", "0x1.000#10", 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",
20,
Nearest,
"1.0000000",
"0x1.00000#20",
Greater,
);
test(
"-1/1000000",
53,
Down,
"0.99999999999949996",
"0x0.ffffffffff7340#53",
Less,
);
test(
"-1/1000000",
53,
Up,
"0.99999999999950007",
"0x0.ffffffffff7348#53",
Greater,
);
test(
"-1/1000000",
53,
Floor,
"0.99999999999949996",
"0x0.ffffffffff7340#53",
Less,
);
test(
"-1/1000000",
53,
Ceiling,
"0.99999999999950007",
"0x0.ffffffffff7348#53",
Greater,
);
test(
"-1/1000000",
53,
Nearest,
"0.99999999999949996",
"0x0.ffffffffff7340#53",
Less,
);
test(
"-1/1000000",
100,
Nearest,
"0.99999999999950000000000004166665",
"0x0.ffffffffff734333f690bc5c6#100",
Less,
);
test(
"1/1000000000000000000000000",
1,
Down,
"0.50",
"0x0.8#1",
Less,
);
test(
"1/1000000000000000000000000",
1,
Up,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/1000000000000000000000000",
1,
Floor,
"0.50",
"0x0.8#1",
Less,
);
test(
"1/1000000000000000000000000",
1,
Ceiling,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/1000000000000000000000000",
1,
Nearest,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/1000000000000000000000000",
5,
Nearest,
"1.00",
"0x1.0#5",
Greater,
);
test(
"1/1000000000000000000000000",
10,
Down,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1/1000000000000000000000000",
10,
Up,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1000000000000000000000000",
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1/1000000000000000000000000",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1000000000000000000000000",
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1000000000000000000000000",
20,
Nearest,
"1.0000000",
"0x1.00000#20",
Greater,
);
test(
"1/1000000000000000000000000",
53,
Down,
"0.99999999999999989",
"0x0.fffffffffffff8#53",
Less,
);
test(
"1/1000000000000000000000000",
53,
Up,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1/1000000000000000000000000",
53,
Floor,
"0.99999999999999989",
"0x0.fffffffffffff8#53",
Less,
);
test(
"1/1000000000000000000000000",
53,
Ceiling,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1/1000000000000000000000000",
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1/1000000000000000000000000",
100,
Nearest,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
1,
Down,
"4.9e-32",
"0x1.0E-26#1",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
1,
Up,
"9.9e-32",
"0x2.0E-26#1",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
1,
Floor,
"4.9e-32",
"0x1.0E-26#1",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
1,
Ceiling,
"9.9e-32",
"0x2.0E-26#1",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
1,
Nearest,
"9.9e-32",
"0x2.0E-26#1",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
5,
Nearest,
"8.63e-32",
"0x1.cE-26#5",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
10,
Down,
"8.4741e-32",
"0x1.b80E-26#10",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
10,
Up,
"8.4837e-32",
"0x1.b88E-26#10",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
10,
Floor,
"8.4741e-32",
"0x1.b80E-26#10",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
10,
Ceiling,
"8.4837e-32",
"0x1.b88E-26#10",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
10,
Nearest,
"8.4741e-32",
"0x1.b80E-26#10",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
20,
Nearest,
"8.4784270e-32",
"0x1.b839aE-26#20",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
53,
Down,
"8.4784276603688996e-32",
"0x1.b839a252049c1E-26#53",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
53,
Up,
"8.4784276603689007e-32",
"0x1.b839a252049c2E-26#53",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
53,
Floor,
"8.4784276603688996e-32",
"0x1.b839a252049c1E-26#53",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
53,
Ceiling,
"8.4784276603689007e-32",
"0x1.b839a252049c2E-26#53",
Greater,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
53,
Nearest,
"8.4784276603688996e-32",
"0x1.b839a252049c1E-26#53",
Less,
);
test(
"124451306656115542615260972311/79228162514264337593543950336",
100,
Nearest,
"8.4784276603688996439587014693888e-32",
"0x1.b839a252049c1114cf98e8042E-26#100",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
1,
Down,
"-2.0e-31",
"-0x4.0E-26#1",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
1,
Up,
"-3.9e-31",
"-0x8.0E-26#1",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
1,
Floor,
"-3.9e-31",
"-0x8.0E-26#1",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
1,
Ceiling,
"-2.0e-31",
"-0x4.0E-26#1",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
1,
Nearest,
"-2.0e-31",
"-0x4.0E-26#1",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
5,
Nearest,
"-2.59e-31",
"-0x5.4E-26#5",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
10,
Down,
"-2.5422e-31",
"-0x5.28E-26#10",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
10,
Up,
"-2.5461e-31",
"-0x5.2aE-26#10",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
10,
Floor,
"-2.5461e-31",
"-0x5.2aE-26#10",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
10,
Ceiling,
"-2.5422e-31",
"-0x5.28E-26#10",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
10,
Nearest,
"-2.5422e-31",
"-0x5.28E-26#10",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
20,
Nearest,
"-2.5435290e-31",
"-0x5.28ad0E-26#20",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
53,
Down,
"-2.5435282981106695e-31",
"-0x5.28ace6f60dd40E-26#53",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
53,
Up,
"-2.5435282981106700e-31",
"-0x5.28ace6f60dd44E-26#53",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
53,
Floor,
"-2.5435282981106700e-31",
"-0x5.28ace6f60dd44E-26#53",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
53,
Ceiling,
"-2.5435282981106695e-31",
"-0x5.28ace6f60dd40E-26#53",
Greater,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
53,
Nearest,
"-2.5435282981106700e-31",
"-0x5.28ace6f60dd44E-26#53",
Less,
);
test(
"373353919968346627845782916933/79228162514264337593543950336",
100,
Nearest,
"-2.5435282981106698931876104408174e-31",
"-0x5.28ace6f60dd4333e6ecab80c8E-26#100",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
1,
Down,
"-0.50",
"-0x0.8#1",
Greater,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
1,
Up,
"-1.0",
"-0x1.0#1",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
1,
Floor,
"-1.0",
"-0x1.0#1",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
1,
Ceiling,
"-0.50",
"-0x0.8#1",
Greater,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
1,
Nearest,
"-1.0",
"-0x1.0#1",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
5,
Nearest,
"-1.00",
"-0x1.0#5",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
10,
Down,
"-0.99902",
"-0x0.ffc#10",
Greater,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
10,
Up,
"-1.0000",
"-0x1.000#10",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
10,
Floor,
"-1.0000",
"-0x1.000#10",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
10,
Ceiling,
"-0.99902",
"-0x0.ffc#10",
Greater,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
20,
Nearest,
"-1.0000000",
"-0x1.00000#20",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
53,
Down,
"-0.99999999999999989",
"-0x0.fffffffffffff8#53",
Greater,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
53,
Up,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
53,
Floor,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
53,
Ceiling,
"-0.99999999999999989",
"-0x0.fffffffffffff8#53",
Greater,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Less,
);
test(
"124451306656115542615260972311/39614081257132168796771975168",
100,
Nearest,
"-1.0000000000000000000000000000000",
"-0x1.0000000000000000000000000#100",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
1,
Down,
"4.9e-32",
"0x1.0E-26#1",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
1,
Up,
"9.9e-32",
"0x2.0E-26#1",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
1,
Floor,
"4.9e-32",
"0x1.0E-26#1",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
1,
Ceiling,
"9.9e-32",
"0x2.0E-26#1",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
1,
Nearest,
"9.9e-32",
"0x2.0E-26#1",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
5,
Nearest,
"8.63e-32",
"0x1.cE-26#5",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
10,
Down,
"8.4741e-32",
"0x1.b80E-26#10",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
10,
Up,
"8.4837e-32",
"0x1.b88E-26#10",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
10,
Floor,
"8.4741e-32",
"0x1.b80E-26#10",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
10,
Ceiling,
"8.4837e-32",
"0x1.b88E-26#10",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
10,
Nearest,
"8.4741e-32",
"0x1.b80E-26#10",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
20,
Nearest,
"8.4784270e-32",
"0x1.b839aE-26#20",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
53,
Down,
"8.4784276603688996e-32",
"0x1.b839a252049c1E-26#53",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
53,
Up,
"8.4784276603689007e-32",
"0x1.b839a252049c2E-26#53",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
53,
Floor,
"8.4784276603688996e-32",
"0x1.b839a252049c1E-26#53",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
53,
Ceiling,
"8.4784276603689007e-32",
"0x1.b839a252049c2E-26#53",
Greater,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
53,
Nearest,
"8.4784276603688996e-32",
"0x1.b839a252049c1E-26#53",
Less,
);
test(
"-124451306656115542615260972311/79228162514264337593543950336",
100,
Nearest,
"8.4784276603688996439587014693888e-32",
"0x1.b839a252049c1114cf98e8042E-26#100",
Greater,
);
test(
"1267650600228229401496703205376",
1,
Down,
"0.25",
"0x0.4#1",
Less,
);
test(
"1267650600228229401496703205376",
1,
Up,
"0.50",
"0x0.8#1",
Greater,
);
test(
"1267650600228229401496703205376",
1,
Floor,
"0.25",
"0x0.4#1",
Less,
);
test(
"1267650600228229401496703205376",
1,
Ceiling,
"0.50",
"0x0.8#1",
Greater,
);
test(
"1267650600228229401496703205376",
1,
Nearest,
"0.50",
"0x0.8#1",
Greater,
);
test(
"1267650600228229401496703205376",
5,
Nearest,
"0.484",
"0x0.7c#5",
Less,
);
test(
"1267650600228229401496703205376",
10,
Down,
"0.48877",
"0x0.7d2#10",
Less,
);
test(
"1267650600228229401496703205376",
10,
Up,
"0.48926",
"0x0.7d4#10",
Greater,
);
test(
"1267650600228229401496703205376",
10,
Floor,
"0.48877",
"0x0.7d2#10",
Less,
);
test(
"1267650600228229401496703205376",
10,
Ceiling,
"0.48926",
"0x0.7d4#10",
Greater,
);
test(
"1267650600228229401496703205376",
10,
Nearest,
"0.48926",
"0x0.7d4#10",
Greater,
);
test(
"1267650600228229401496703205376",
20,
Nearest,
"0.48917866",
"0x0.7d3ad0#20",
Greater,
);
test(
"1267650600228229401496703205376",
53,
Down,
"0.48917865697472140",
"0x0.7d3acffd9b8db0#53",
Less,
);
test(
"1267650600228229401496703205376",
53,
Up,
"0.48917865697472146",
"0x0.7d3acffd9b8db4#53",
Greater,
);
test(
"1267650600228229401496703205376",
53,
Floor,
"0.48917865697472140",
"0x0.7d3acffd9b8db0#53",
Less,
);
test(
"1267650600228229401496703205376",
53,
Ceiling,
"0.48917865697472146",
"0x0.7d3acffd9b8db4#53",
Greater,
);
test(
"1267650600228229401496703205376",
53,
Nearest,
"0.48917865697472146",
"0x0.7d3acffd9b8db4#53",
Greater,
);
test(
"1267650600228229401496703205376",
100,
Nearest,
"0.48917865697472144990578930875139",
"0x0.7d3acffd9b8db34b71d86c7ff0#100",
Greater,
);
test(
"1/1267650600228229401496703205376",
1,
Down,
"0.50",
"0x0.8#1",
Less,
);
test(
"1/1267650600228229401496703205376",
1,
Up,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/1267650600228229401496703205376",
1,
Floor,
"0.50",
"0x0.8#1",
Less,
);
test(
"1/1267650600228229401496703205376",
1,
Ceiling,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/1267650600228229401496703205376",
1,
Nearest,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/1267650600228229401496703205376",
5,
Nearest,
"1.00",
"0x1.0#5",
Greater,
);
test(
"1/1267650600228229401496703205376",
10,
Down,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1/1267650600228229401496703205376",
10,
Up,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1267650600228229401496703205376",
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1/1267650600228229401496703205376",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1267650600228229401496703205376",
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1267650600228229401496703205376",
20,
Nearest,
"1.0000000",
"0x1.00000#20",
Greater,
);
test(
"1/1267650600228229401496703205376",
53,
Down,
"0.99999999999999989",
"0x0.fffffffffffff8#53",
Less,
);
test(
"1/1267650600228229401496703205376",
53,
Up,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1/1267650600228229401496703205376",
53,
Floor,
"0.99999999999999989",
"0x0.fffffffffffff8#53",
Less,
);
test(
"1/1267650600228229401496703205376",
53,
Ceiling,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1/1267650600228229401496703205376",
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1/1267650600228229401496703205376",
100,
Nearest,
"1.0000000000000000000000000000000",
"0x1.0000000000000000000000000#100",
Greater,
);
}
#[test]
#[should_panic]
fn cos_rational_prec_fail() {
Float::cos_rational_prec(Rational::ONE, 0);
}
#[test]
#[should_panic]
fn cos_rational_prec_ref_fail() {
Float::cos_rational_prec_ref(&Rational::ONE, 0);
}
#[test]
#[should_panic]
fn cos_rational_prec_round_fail_1() {
Float::cos_rational_prec_round(Rational::ONE, 0, Floor);
}
#[test]
#[should_panic]
fn cos_rational_prec_round_fail_2() {
Float::cos_rational_prec_round(Rational::ONE, 10, Exact);
}
#[test]
#[should_panic]
fn cos_rational_prec_round_ref_fail() {
Float::cos_rational_prec_round_ref(&Rational::ONE, 10, Exact);
}
#[allow(clippy::needless_pass_by_value)]
fn cos_rational_prec_round_properties_helper(x: Rational, prec: u64, rm: RoundingMode) {
let (c, o) = Float::cos_rational_prec_round(x.clone(), prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = Float::cos_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.le_abs(&1u32));
let (c_neg, o_neg) = Float::cos_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_cos_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::cos_rational_prec_round_ref(&x, prec, rm);
assert_eq!(ComparableFloatRef(&s), ComparableFloatRef(&c));
assert_eq!(oo, Equal);
}
} else {
assert_panic!(Float::cos_rational_prec_round_ref(&x, prec, Exact));
}
}
#[test]
fn cos_rational_prec_round_properties() {
rational_unsigned_rounding_mode_triple_gen_var_10().test_properties(|(x, prec, rm)| {
cos_rational_prec_round_properties_helper(x, prec, rm);
});
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::cos_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 cos_rational_prec_properties_helper(x: Rational, prec: u64) {
let (c, o) = Float::cos_rational_prec(x.clone(), prec);
assert!(c.is_valid());
let (c_alt, o_alt) = Float::cos_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::cos_rational_prec_round_ref(&x, prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
assert!(c.le_abs(&1u32));
let (rug_c, rug_o) = rug_cos_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.cos_prec(prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
}
}
#[test]
fn cos_rational_prec_properties() {
rational_unsigned_pair_gen_var_3().test_properties(|(x, prec)| {
cos_rational_prec_properties_helper(x, prec);
});
}
#[cfg(not(feature = "32_bit_limbs"))]
#[test]
fn test_cos_rational_huge() {
let x = Rational::power_of_2(1i64 << 30);
let (c, o) = Float::cos_rational_prec_round_ref(&x, 10, Nearest);
assert_eq!(c.to_string(), "-0.77832");
assert_eq!(to_hex_string(&c), "-0x0.c74#10");
assert_eq!(o, Greater);
}
#[cfg(not(feature = "32_bit_limbs"))]
#[test]
fn test_cos_rational_underflow() {
let p = (1u64 << 30) + 64;
let min_positive = Float::one_prec(10) >> (1u64 << 30);
let mut pi = Float::pi_prec_round(p, Floor).0;
let x_lo = Rational::exact_from(&(&pi >> 1u32));
let (c, o) = Float::cos_rational_prec_round_ref(&x_lo, 10, Ceiling);
assert_eq!(ComparableFloatRef(&c), ComparableFloatRef(&min_positive));
assert_eq!(o, Greater);
pi.increment();
let x_hi = Rational::exact_from(&(pi >> 1u32));
let (c, o) = Float::cos_rational_prec_round_ref(&x_hi, 10, Nearest);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::NEGATIVE_ZERO));
assert_eq!(o, Greater);
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_cos_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_cos_rational::<T>(&x)),
NiceFloat(out)
);
}
test::<f32>("0", 1.0);
test::<f32>("1", 0.5403023);
test::<f32>("1/2", 0.87758255);
test::<f32>("1/3", 0.94495696);
test::<f32>("3/5", 0.8253356);
test::<f32>("22/7", -0.9999992);
test::<f32>("355/113", -1.0);
test::<f32>("1000000", 0.93675214);
test::<f32>("1/1000000", 1.0);
test::<f32>("1/1000000000000000000000000", 1.0);
test::<f32>("-1", 0.5403023);
test::<f32>("-1/2", 0.87758255);
test::<f32>("-1/3", 0.94495696);
test::<f32>("-22/7", -0.9999992);
test::<f32>("-1000000", 0.93675214);
test::<f32>("10000", -0.95215535);
test::<f64>("0", 1.0);
test::<f64>("1", 0.5403023058681398);
test::<f64>("1/2", 0.8775825618903728);
test::<f64>("1/3", 0.9449569463147377);
test::<f64>("3/5", 0.8253356149096783);
test::<f64>("22/7", -0.999999200533553);
test::<f64>("355/113", -0.9999999999999645);
test::<f64>("1000000", 0.9367521275331447);
test::<f64>("1/1000000", 0.9999999999995);
test::<f64>("1/1000000000000000000000000", 1.0);
test::<f64>("-1", 0.5403023058681398);
test::<f64>("-1/2", 0.8775825618903728);
test::<f64>("-1/3", 0.9449569463147377);
test::<f64>("-22/7", -0.999999200533553);
test::<f64>("-1000000", 0.9367521275331447);
test::<f64>("10000", -0.9521553682590148);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_cos_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_cos_rational::<T>(&x);
assert!(c >= T::NEGATIVE_ONE && c <= T::ONE);
assert_eq!(
NiceFloat(primitive_float_cos_rational::<T>(&-&x)),
NiceFloat(c)
);
let rug_c = rug_cos_rational_prec(&x, T::MANTISSA_WIDTH + 1).0;
let rug_c: T = T::exact_from(&<Float as From<&rug::Float>>::from(&rug_c));
assert_eq!(NiceFloat(rug_c), NiceFloat(c));
});
primitive_float_gen::<T>().test_properties(|x| {
if x.is_finite() {
assert_eq!(
NiceFloat(primitive_float_cos_rational::<T>(&Rational::exact_from(x))),
NiceFloat(primitive_float_cos(x))
);
}
});
}
#[test]
fn primitive_float_cos_rational_properties() {
apply_fn_to_primitive_floats!(primitive_float_cos_rational_properties_helper);
}
#[test]
fn test_cos_with_period_prec_round() {
let test = |s, s_hex, u: u64, 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().cos_with_period_prec_round(u, 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.cos_with_period_prec_round_ref(u, 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.cos_with_period_prec_round_assign(u, 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)
&& u32::try_from(u).is_ok()
{
let (rug_c, rug_o) =
rug_cos_with_period_prec_round(&rug::Float::exact_from(&x), u, prec, rug_rm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
};
test("NaN", "NaN", 4, 10, Nearest, "NaN", "NaN", Equal);
test("Infinity", "Infinity", 4, 10, Nearest, "NaN", "NaN", Equal);
test(
"-Infinity",
"-Infinity",
4,
10,
Nearest,
"NaN",
"NaN",
Equal,
);
test(
"0.0",
"0x0.0",
4,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"-0.0",
"-0x0.0",
4,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test("1.0", "0x1.0#1", 0, 10, Nearest, "NaN", "NaN", Equal);
test("NaN", "NaN", 0, 10, Nearest, "NaN", "NaN", Equal);
test("0.0", "0x0.0", 0, 10, Nearest, "NaN", "NaN", Equal);
test(
"0.0",
"0x0.0",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"0.0",
"0x0.0",
360,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"0.0",
"0x0.0",
360,
10,
Exact,
"1.0000",
"0x1.000#10",
Equal,
);
test("90.0", "0x5a.0#6", 360, 10, Nearest, "0.0", "0x0.0", Equal);
test("90.0", "0x5a.0#6", 360, 10, Floor, "0.0", "0x0.0", Equal);
test("90.0", "0x5a.0#6", 360, 10, Exact, "0.0", "0x0.0", Equal);
test(
"180.0",
"0xb4.0#6",
360,
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"180.0",
"0xb4.0#6",
360,
10,
Floor,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"180.0",
"0xb4.0#6",
360,
10,
Exact,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"270.0",
"0x10e.0#8",
360,
10,
Nearest,
"0.0",
"0x0.0",
Equal,
);
test("270.0", "0x10e.0#8", 360, 10, Floor, "0.0", "0x0.0", Equal);
test("270.0", "0x10e.0#8", 360, 10, Exact, "0.0", "0x0.0", Equal);
test(
"360.0",
"0x168.0#6",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"360.0",
"0x168.0#6",
360,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"360.0",
"0x168.0#6",
360,
10,
Exact,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"60.0",
"0x3c.0#4",
360,
10,
Nearest,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"60.0",
"0x3c.0#4",
360,
10,
Floor,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"60.0",
"0x3c.0#4",
360,
10,
Exact,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"120.0",
"0x78.0#4",
360,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"120.0",
"0x78.0#4",
360,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"120.0",
"0x78.0#4",
360,
10,
Exact,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"240.0",
"0xf.0E+1#4",
360,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"240.0",
"0xf.0E+1#4",
360,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"240.0",
"0xf.0E+1#4",
360,
10,
Exact,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"300.0",
"0x12c.0#7",
360,
10,
Nearest,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"300.0",
"0x12c.0#7",
360,
10,
Floor,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"300.0",
"0x12c.0#7",
360,
10,
Exact,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"450.0",
"0x1c2.0#8",
360,
10,
Nearest,
"0.0",
"0x0.0",
Equal,
);
test("450.0", "0x1c2.0#8", 360, 10, Floor, "0.0", "0x0.0", Equal);
test("450.0", "0x1c2.0#8", 360, 10, Exact, "0.0", "0x0.0", Equal);
test(
"720.0",
"0x2.dE+2#6",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"720.0",
"0x2.dE+2#6",
360,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"720.0",
"0x2.dE+2#6",
360,
10,
Exact,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
1,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
1,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
1,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
1,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"1.0",
"0x1.0#1",
2,
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
2,
10,
Floor,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
2,
10,
Ceiling,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
2,
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test(
"1.0",
"0x1.0#1",
3,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
3,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
3,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
3,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test("1.0", "0x1.0#1", 4, 10, Nearest, "0.0", "0x0.0", Equal);
test("1.0", "0x1.0#1", 4, 10, Floor, "0.0", "0x0.0", Equal);
test("1.0", "0x1.0#1", 4, 10, Ceiling, "0.0", "0x0.0", Equal);
test("1.0", "0x1.0#1", 4, 53, Nearest, "0.0", "0x0.0", Equal);
test(
"1.0",
"0x1.0#1",
6,
10,
Nearest,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
6,
10,
Floor,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
6,
10,
Ceiling,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"1.0",
"0x1.0#1",
6,
53,
Nearest,
"0.50000000000000000",
"0x0.80000000000000#53",
Equal,
);
test(
"1.0",
"0x1.0#1",
7,
10,
Nearest,
"0.62305",
"0x0.9f8#10",
Less,
);
test(
"1.0",
"0x1.0#1",
7,
10,
Floor,
"0.62305",
"0x0.9f8#10",
Less,
);
test(
"1.0",
"0x1.0#1",
7,
10,
Ceiling,
"0.62402",
"0x0.9fc#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
12,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
12,
10,
Floor,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"1.0",
"0x1.0#1",
12,
10,
Ceiling,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
360,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0",
"0x1.0#1",
360,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
360,
53,
Nearest,
"0.99984769515639127",
"0x0.fff604bfad7c50#53",
Greater,
);
test(
"1.0",
"0x1.0#1",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0",
"0x1.0#1",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0",
"0x1.0#1",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"0.50",
"0x0.8#1",
1,
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"0.50",
"0x0.8#1",
1,
10,
Floor,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"0.50",
"0x0.8#1",
1,
10,
Ceiling,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"0.50",
"0x0.8#1",
1,
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test("0.50", "0x0.8#1", 2, 10, Nearest, "0.0", "0x0.0", Equal);
test("0.50", "0x0.8#1", 2, 10, Floor, "0.0", "0x0.0", Equal);
test("0.50", "0x0.8#1", 2, 10, Ceiling, "0.0", "0x0.0", Equal);
test("0.50", "0x0.8#1", 2, 53, Nearest, "0.0", "0x0.0", Equal);
test(
"0.50",
"0x0.8#1",
3,
10,
Nearest,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"0.50",
"0x0.8#1",
3,
10,
Floor,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"0.50",
"0x0.8#1",
3,
10,
Ceiling,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"0.50",
"0x0.8#1",
3,
53,
Nearest,
"0.50000000000000000",
"0x0.80000000000000#53",
Equal,
);
test(
"0.50",
"0x0.8#1",
4,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"0.50",
"0x0.8#1",
4,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"0.50",
"0x0.8#1",
4,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
4,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test(
"0.50",
"0x0.8#1",
6,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
6,
10,
Floor,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"0.50",
"0x0.8#1",
6,
10,
Ceiling,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
6,
53,
Nearest,
"0.86602540378443860",
"0x0.ddb3d742c26550#53",
Less,
);
test(
"0.50",
"0x0.8#1",
7,
10,
Nearest,
"0.90137",
"0x0.e6c#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
7,
10,
Floor,
"0.90039",
"0x0.e68#10",
Less,
);
test(
"0.50",
"0x0.8#1",
7,
10,
Ceiling,
"0.90137",
"0x0.e6c#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
12,
10,
Nearest,
"0.96582",
"0x0.f74#10",
Less,
);
test(
"0.50",
"0x0.8#1",
12,
10,
Floor,
"0.96582",
"0x0.f74#10",
Less,
);
test(
"0.50",
"0x0.8#1",
12,
10,
Ceiling,
"0.96680",
"0x0.f78#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
360,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.50",
"0x0.8#1",
360,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
360,
53,
Nearest,
"0.99996192306417131",
"0x0.fffd812cce4e68#53",
Greater,
);
test(
"0.50",
"0x0.8#1",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.50",
"0x0.8#1",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.50",
"0x0.8#1",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.50",
"0x0.8#1",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test("0.25", "0x0.4#1", 1, 10, Nearest, "0.0", "0x0.0", Equal);
test("0.25", "0x0.4#1", 1, 10, Floor, "0.0", "0x0.0", Equal);
test("0.25", "0x0.4#1", 1, 10, Ceiling, "0.0", "0x0.0", Equal);
test("0.25", "0x0.4#1", 1, 53, Nearest, "0.0", "0x0.0", Equal);
test(
"0.25",
"0x0.4#1",
2,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"0.25",
"0x0.4#1",
2,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"0.25",
"0x0.4#1",
2,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
2,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test(
"0.25",
"0x0.4#1",
3,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
3,
10,
Floor,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"0.25",
"0x0.4#1",
3,
10,
Ceiling,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
3,
53,
Nearest,
"0.86602540378443860",
"0x0.ddb3d742c26550#53",
Less,
);
test(
"0.25",
"0x0.4#1",
4,
10,
Nearest,
"0.92383",
"0x0.ec8#10",
Less,
);
test(
"0.25",
"0x0.4#1",
4,
10,
Floor,
"0.92383",
"0x0.ec8#10",
Less,
);
test(
"0.25",
"0x0.4#1",
4,
10,
Ceiling,
"0.92480",
"0x0.ecc#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
4,
53,
Nearest,
"0.92387953251128674",
"0x0.ec835e79946a30#53",
Less,
);
test(
"0.25",
"0x0.4#1",
6,
10,
Nearest,
"0.96582",
"0x0.f74#10",
Less,
);
test(
"0.25",
"0x0.4#1",
6,
10,
Floor,
"0.96582",
"0x0.f74#10",
Less,
);
test(
"0.25",
"0x0.4#1",
6,
10,
Ceiling,
"0.96680",
"0x0.f78#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
6,
53,
Nearest,
"0.96592582628906831",
"0x0.f746ea3a45f8a8#53",
Greater,
);
test(
"0.25",
"0x0.4#1",
7,
10,
Nearest,
"0.97461",
"0x0.f98#10",
Less,
);
test(
"0.25",
"0x0.4#1",
7,
10,
Floor,
"0.97461",
"0x0.f98#10",
Less,
);
test(
"0.25",
"0x0.4#1",
7,
10,
Ceiling,
"0.97559",
"0x0.f9c#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
12,
10,
Nearest,
"0.99121",
"0x0.fdc#10",
Less,
);
test(
"0.25",
"0x0.4#1",
12,
10,
Floor,
"0.99121",
"0x0.fdc#10",
Less,
);
test(
"0.25",
"0x0.4#1",
12,
10,
Ceiling,
"0.99219",
"0x0.fe0#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
360,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.25",
"0x0.4#1",
360,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
360,
53,
Nearest,
"0.99999048072073449",
"0x0.ffff604b01c270#53",
Greater,
);
test(
"0.25",
"0x0.4#1",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.25",
"0x0.4#1",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.25",
"0x0.4#1",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.5",
"0x1.8#2",
1,
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"1.5",
"0x1.8#2",
1,
10,
Floor,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"1.5",
"0x1.8#2",
1,
10,
Ceiling,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"1.5",
"0x1.8#2",
1,
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test("1.5", "0x1.8#2", 2, 10, Nearest, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 2, 10, Floor, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 2, 10, Ceiling, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 2, 53, Nearest, "0.0", "0x0.0", Equal);
test(
"1.5",
"0x1.8#2",
3,
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"1.5",
"0x1.8#2",
3,
10,
Floor,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"1.5",
"0x1.8#2",
3,
10,
Ceiling,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"1.5",
"0x1.8#2",
3,
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test(
"1.5",
"0x1.8#2",
4,
10,
Nearest,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
4,
10,
Floor,
"-0.70801",
"-0x0.b54#10",
Less,
);
test(
"1.5",
"0x1.8#2",
4,
10,
Ceiling,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
4,
53,
Nearest,
"-0.70710678118654757",
"-0x0.b504f333f9de68#53",
Less,
);
test("1.5", "0x1.8#2", 6, 10, Nearest, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 6, 10, Floor, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 6, 10, Ceiling, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 6, 53, Nearest, "0.0", "0x0.0", Equal);
test(
"1.5",
"0x1.8#2",
7,
10,
Nearest,
"0.22241",
"0x0.38f#10",
Less,
);
test(
"1.5",
"0x1.8#2",
7,
10,
Floor,
"0.22241",
"0x0.38f#10",
Less,
);
test(
"1.5",
"0x1.8#2",
7,
10,
Ceiling,
"0.22266",
"0x0.390#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
12,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"1.5",
"0x1.8#2",
12,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"1.5",
"0x1.8#2",
12,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
360,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.5",
"0x1.8#2",
360,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
360,
53,
Nearest,
"0.99965732497555726",
"0x0.ffe98addfa13a8#53",
Less,
);
test(
"1.5",
"0x1.8#2",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.5",
"0x1.8#2",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.5",
"0x1.8#2",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.5",
"0x1.8#2",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"2.0",
"0x2.0#1",
1,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
1,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
1,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
1,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"2.0",
"0x2.0#1",
2,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
2,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
2,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
2,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"2.0",
"0x2.0#1",
3,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
3,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
3,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
3,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test(
"2.0",
"0x2.0#1",
4,
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
4,
10,
Floor,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
4,
10,
Ceiling,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
4,
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test(
"2.0",
"0x2.0#1",
6,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
6,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
6,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
6,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test(
"2.0",
"0x2.0#1",
7,
10,
Nearest,
"-0.22241",
"-0x0.38f#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
7,
10,
Floor,
"-0.22266",
"-0x0.390#10",
Less,
);
test(
"2.0",
"0x2.0#1",
7,
10,
Ceiling,
"-0.22241",
"-0x0.38f#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
12,
10,
Nearest,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
12,
10,
Floor,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
12,
10,
Ceiling,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"2.0",
"0x2.0#1",
360,
10,
Nearest,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"2.0",
"0x2.0#1",
360,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"2.0",
"0x2.0#1",
360,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
360,
53,
Nearest,
"0.99939082701909576",
"0x0.ffd813c5f82b38#53",
Greater,
);
test(
"2.0",
"0x2.0#1",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"2.0",
"0x2.0#1",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"2.0",
"0x2.0#1",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"3.0",
"0x3.0#2",
1,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
1,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
1,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
1,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"3.0",
"0x3.0#2",
2,
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
2,
10,
Floor,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
2,
10,
Ceiling,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
2,
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test(
"3.0",
"0x3.0#2",
3,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
3,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
3,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
3,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test("3.0", "0x3.0#2", 4, 10, Nearest, "0.0", "0x0.0", Equal);
test("3.0", "0x3.0#2", 4, 10, Floor, "0.0", "0x0.0", Equal);
test("3.0", "0x3.0#2", 4, 10, Ceiling, "0.0", "0x0.0", Equal);
test("3.0", "0x3.0#2", 4, 53, Nearest, "0.0", "0x0.0", Equal);
test(
"3.0",
"0x3.0#2",
6,
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
6,
10,
Floor,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
6,
10,
Ceiling,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"3.0",
"0x3.0#2",
6,
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test(
"3.0",
"0x3.0#2",
7,
10,
Nearest,
"-0.90137",
"-0x0.e6c#10",
Less,
);
test(
"3.0",
"0x3.0#2",
7,
10,
Floor,
"-0.90137",
"-0x0.e6c#10",
Less,
);
test(
"3.0",
"0x3.0#2",
7,
10,
Ceiling,
"-0.90039",
"-0x0.e68#10",
Greater,
);
test("3.0", "0x3.0#2", 12, 10, Nearest, "0.0", "0x0.0", Equal);
test("3.0", "0x3.0#2", 12, 10, Floor, "0.0", "0x0.0", Equal);
test("3.0", "0x3.0#2", 12, 10, Ceiling, "0.0", "0x0.0", Equal);
test(
"3.0",
"0x3.0#2",
360,
10,
Nearest,
"0.99902",
"0x0.ffc#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
360,
10,
Floor,
"0.99805",
"0x0.ff8#10",
Less,
);
test(
"3.0",
"0x3.0#2",
360,
10,
Ceiling,
"0.99902",
"0x0.ffc#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
360,
53,
Nearest,
"0.99862953475457383",
"0x0.ffa62f689730e8#53",
Less,
);
test(
"3.0",
"0x3.0#2",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"3.0",
"0x3.0#2",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"3.0",
"0x3.0#2",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
1,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
1,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
1,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
1,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
2,
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
2,
10,
Floor,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
2,
10,
Ceiling,
"-1.0000",
"-0x1.000#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
2,
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
3,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
3,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
3,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
3,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test("-1.0", "-0x1.0#1", 4, 10, Nearest, "0.0", "0x0.0", Equal);
test("-1.0", "-0x1.0#1", 4, 10, Floor, "0.0", "0x0.0", Equal);
test("-1.0", "-0x1.0#1", 4, 10, Ceiling, "0.0", "0x0.0", Equal);
test("-1.0", "-0x1.0#1", 4, 53, Nearest, "0.0", "0x0.0", Equal);
test(
"-1.0",
"-0x1.0#1",
6,
10,
Nearest,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
6,
10,
Floor,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
6,
10,
Ceiling,
"0.50000",
"0x0.800#10",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
6,
53,
Nearest,
"0.50000000000000000",
"0x0.80000000000000#53",
Equal,
);
test(
"-1.0",
"-0x1.0#1",
7,
10,
Nearest,
"0.62305",
"0x0.9f8#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
7,
10,
Floor,
"0.62305",
"0x0.9f8#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
7,
10,
Ceiling,
"0.62402",
"0x0.9fc#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
12,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
12,
10,
Floor,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
12,
10,
Ceiling,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
360,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
360,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
360,
53,
Nearest,
"0.99984769515639127",
"0x0.fff604bfad7c50#53",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"100.0",
"0x64.0#5",
1,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
1,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
1,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
1,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"100.0",
"0x64.0#5",
2,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
2,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
2,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
2,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"100.0",
"0x64.0#5",
3,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
3,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
3,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
3,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test(
"100.0",
"0x64.0#5",
4,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
4,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
4,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
4,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"100.0",
"0x64.0#5",
6,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
6,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
6,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
6,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test(
"100.0",
"0x64.0#5",
7,
10,
Nearest,
"-0.22241",
"-0x0.38f#10",
Greater,
);
test(
"100.0",
"0x64.0#5",
7,
10,
Floor,
"-0.22266",
"-0x0.390#10",
Less,
);
test(
"100.0",
"0x64.0#5",
7,
10,
Ceiling,
"-0.22241",
"-0x0.38f#10",
Greater,
);
test(
"100.0",
"0x64.0#5",
12,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
12,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
12,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"100.0",
"0x64.0#5",
360,
10,
Nearest,
"-0.17358",
"-0x0.2c7#10",
Greater,
);
test(
"100.0",
"0x64.0#5",
360,
10,
Floor,
"-0.17383",
"-0x0.2c8#10",
Less,
);
test(
"100.0",
"0x64.0#5",
360,
10,
Ceiling,
"-0.17358",
"-0x0.2c7#10",
Greater,
);
test(
"100.0",
"0x64.0#5",
360,
53,
Nearest,
"-0.17364817766693036",
"-0x0.2c7434fc16e714#53",
Less,
);
test(
"100.0",
"0x64.0#5",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"100.0",
"0x64.0#5",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"100.0",
"0x64.0#5",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"100.0",
"0x64.0#5",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"100.0",
"0x64.0#5",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"100.0",
"0x64.0#5",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"100.0",
"0x64.0#5",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1,
10,
Nearest,
"-0.96191",
"-0x0.f64#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1,
10,
Floor,
"-0.96289",
"-0x0.f68#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1,
10,
Ceiling,
"-0.96191",
"-0x0.f64#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1,
53,
Nearest,
"-0.96202767158609115",
"-0x0.f647720b4f2da0#53",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
2,
10,
Nearest,
"-0.13770",
"-0x0.234#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
2,
10,
Floor,
"-0.13794",
"-0x0.235#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
2,
10,
Ceiling,
"-0.13770",
"-0x0.234#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
2,
53,
Nearest,
"-0.13779029068462850",
"-0x0.23463978326254#53",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
3,
10,
Nearest,
"0.57715",
"0x0.93c#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
3,
10,
Floor,
"0.57715",
"0x0.93c#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
3,
10,
Ceiling,
"0.57812",
"0x0.940#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
3,
53,
Nearest,
"0.57757270342226230",
"0x0.93dbce0042cbe8#53",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
4,
10,
Nearest,
"0.65625",
"0x0.a80#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
4,
10,
Floor,
"0.65625",
"0x0.a80#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
4,
10,
Ceiling,
"0.65723",
"0x0.a84#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
4,
53,
Nearest,
"0.65658575575296008",
"0x0.a816010bfa78e8#53",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
6,
10,
Nearest,
"-0.88770",
"-0x0.e34#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
6,
10,
Floor,
"-0.88867",
"-0x0.e38#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
6,
10,
Ceiling,
"-0.88770",
"-0x0.e34#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
6,
53,
Nearest,
"-0.88813644881354303",
"-0x0.e35ce90a0a2cc0#53",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
7,
10,
Nearest,
"-0.65430",
"-0x0.a78#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
7,
10,
Floor,
"-0.65430",
"-0x0.a78#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
7,
10,
Ceiling,
"-0.65332",
"-0x0.a74#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
12,
10,
Nearest,
"-0.23657",
"-0x0.3c9#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
12,
10,
Floor,
"-0.23657",
"-0x0.3c9#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
12,
10,
Ceiling,
"-0.23633",
"-0x0.3c8#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
360,
10,
Nearest,
"-0.55176",
"-0x0.8d4#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
360,
10,
Floor,
"-0.55176",
"-0x0.8d4#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
360,
10,
Ceiling,
"-0.55078",
"-0x0.8d0#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
360,
53,
Nearest,
"-0.55129644428558244",
"-0x0.8d21c3869b8fc8#53",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"123.45600000000000",
"0x7b.74bc6a7ef9dc#53",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
2,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
2,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
2,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
2,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
3,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
3,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
3,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
3,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
4,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
4,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
4,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
4,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
6,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
6,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
6,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
6,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
7,
10,
Nearest,
"-0.90137",
"-0x0.e6c#10",
Less,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
7,
10,
Floor,
"-0.90137",
"-0x0.e6c#10",
Less,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
7,
10,
Ceiling,
"-0.90039",
"-0x0.e68#10",
Greater,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
12,
10,
Nearest,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
12,
10,
Floor,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
12,
10,
Ceiling,
"-0.50000",
"-0x0.800#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
360,
10,
Nearest,
"0.17358",
"0x0.2c7#10",
Less,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
360,
10,
Floor,
"0.17358",
"0x0.2c7#10",
Less,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
360,
10,
Ceiling,
"0.17383",
"0x0.2c8#10",
Greater,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
360,
53,
Nearest,
"0.17364817766693036",
"0x0.2c7434fc16e714#53",
Greater,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1000000,
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1099511627776,
10,
Nearest,
"0.99805",
"0x0.ff8#10",
Less,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1099511627776,
10,
Floor,
"0.99805",
"0x0.ff8#10",
Less,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1099511627776,
10,
Ceiling,
"0.99902",
"0x0.ffc#10",
Greater,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1099511627776,
53,
Nearest,
"0.99836765520217097",
"0x0.ff9505cc7a3f50#53",
Less,
);
test("-0.75", "-0x0.c#2", 1, 10, Nearest, "0.0", "0x0.0", Equal);
test("-0.75", "-0x0.c#2", 1, 10, Floor, "0.0", "0x0.0", Equal);
test("-0.75", "-0x0.c#2", 1, 10, Ceiling, "0.0", "0x0.0", Equal);
test("-0.75", "-0x0.c#2", 1, 53, Nearest, "0.0", "0x0.0", Equal);
test(
"-0.75",
"-0x0.c#2",
2,
10,
Nearest,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
2,
10,
Floor,
"-0.70801",
"-0x0.b54#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
2,
10,
Ceiling,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
2,
53,
Nearest,
"-0.70710678118654757",
"-0x0.b504f333f9de68#53",
Less,
);
test("-0.75", "-0x0.c#2", 3, 10, Nearest, "0.0", "0x0.0", Equal);
test("-0.75", "-0x0.c#2", 3, 10, Floor, "0.0", "0x0.0", Equal);
test("-0.75", "-0x0.c#2", 3, 10, Ceiling, "0.0", "0x0.0", Equal);
test("-0.75", "-0x0.c#2", 3, 53, Nearest, "0.0", "0x0.0", Equal);
test(
"-0.75",
"-0x0.c#2",
4,
10,
Nearest,
"0.38281",
"0x0.620#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
4,
10,
Floor,
"0.38232",
"0x0.61e#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
4,
10,
Ceiling,
"0.38281",
"0x0.620#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
4,
53,
Nearest,
"0.38268343236508978",
"0x0.61f78a9abaa58c#53",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
6,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
6,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
6,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
6,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
7,
10,
Nearest,
"0.78223",
"0x0.c84#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
7,
10,
Floor,
"0.78125",
"0x0.c80#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
7,
10,
Ceiling,
"0.78223",
"0x0.c84#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
12,
10,
Nearest,
"0.92383",
"0x0.ec8#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
12,
10,
Floor,
"0.92383",
"0x0.ec8#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
12,
10,
Ceiling,
"0.92480",
"0x0.ecc#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
360,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
360,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
360,
53,
Nearest,
"0.99991432757400700",
"0x0.fffa62a7bb70e0#53",
Less,
);
test(
"-0.75",
"-0x0.c#2",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"-0.75",
"-0x0.c#2",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"-0.75",
"-0x0.c#2",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
2,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
2,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
2,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
2,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
3,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
3,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
3,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
3,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
4,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
4,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
4,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
4,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
6,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
6,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
6,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
6,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
7,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
7,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
7,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
12,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
12,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
12,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
360,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
360,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
360,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.0000000000000000e-10",
"0x6.df37f675ef6ecE-9#53",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"0.12",
"0x0.2#1",
1,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"0.12",
"0x0.2#1",
1,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"0.12",
"0x0.2#1",
1,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
1,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test(
"0.12",
"0x0.2#1",
2,
10,
Nearest,
"0.92383",
"0x0.ec8#10",
Less,
);
test(
"0.12",
"0x0.2#1",
2,
10,
Floor,
"0.92383",
"0x0.ec8#10",
Less,
);
test(
"0.12",
"0x0.2#1",
2,
10,
Ceiling,
"0.92480",
"0x0.ecc#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
2,
53,
Nearest,
"0.92387953251128674",
"0x0.ec835e79946a30#53",
Less,
);
test(
"0.12",
"0x0.2#1",
3,
10,
Nearest,
"0.96582",
"0x0.f74#10",
Less,
);
test(
"0.12",
"0x0.2#1",
3,
10,
Floor,
"0.96582",
"0x0.f74#10",
Less,
);
test(
"0.12",
"0x0.2#1",
3,
10,
Ceiling,
"0.96680",
"0x0.f78#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
3,
53,
Nearest,
"0.96592582628906831",
"0x0.f746ea3a45f8a8#53",
Greater,
);
test(
"0.12",
"0x0.2#1",
4,
10,
Nearest,
"0.98047",
"0x0.fb0#10",
Less,
);
test(
"0.12",
"0x0.2#1",
4,
10,
Floor,
"0.98047",
"0x0.fb0#10",
Less,
);
test(
"0.12",
"0x0.2#1",
4,
10,
Ceiling,
"0.98145",
"0x0.fb4#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
4,
53,
Nearest,
"0.98078528040323043",
"0x0.fb14be7fbae580#53",
Less,
);
test(
"0.12",
"0x0.2#1",
6,
10,
Nearest,
"0.99121",
"0x0.fdc#10",
Less,
);
test(
"0.12",
"0x0.2#1",
6,
10,
Floor,
"0.99121",
"0x0.fdc#10",
Less,
);
test(
"0.12",
"0x0.2#1",
6,
10,
Ceiling,
"0.99219",
"0x0.fe0#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
6,
53,
Nearest,
"0.99144486137381038",
"0x0.fdcf54976344d8#53",
Less,
);
test(
"0.12",
"0x0.2#1",
7,
10,
Nearest,
"0.99414",
"0x0.fe8#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
7,
10,
Floor,
"0.99316",
"0x0.fe4#10",
Less,
);
test(
"0.12",
"0x0.2#1",
7,
10,
Ceiling,
"0.99414",
"0x0.fe8#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
12,
10,
Nearest,
"0.99805",
"0x0.ff8#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
12,
10,
Floor,
"0.99707",
"0x0.ff4#10",
Less,
);
test(
"0.12",
"0x0.2#1",
12,
10,
Ceiling,
"0.99805",
"0x0.ff8#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
360,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
360,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.12",
"0x0.2#1",
360,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
360,
53,
Nearest,
"0.99999762017735183",
"0x0.ffffd812bd5388#53",
Less,
);
test(
"0.12",
"0x0.2#1",
1000000,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
1000000,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.12",
"0x0.2#1",
1000000,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
1099511627776,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
1099511627776,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"0.12",
"0x0.2#1",
1099511627776,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"0.12",
"0x0.2#1",
1099511627776,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.000000000000000e-30",
"0x1.4484bfeebc2aE-25#48",
1,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"1.000000000000000e-30",
"0x1.4484bfeebc2aE-25#48",
1,
53,
Floor,
"0.99999999999999989",
"0x0.fffffffffffff8#53",
Less,
);
test(
"3.8e30",
"0x3.0E+25#2",
7,
53,
Nearest,
"0.62348980185873348",
"0x0.9f9d07145f6e88#53",
Less,
);
test(
"3.8e30",
"0x3.0E+25#2",
3,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"4.0e-323228490",
"0x1.0E-268435450#1",
18446744073709551615,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"90.000000000000000000000000000808",
"0x5a.000000000000000000000040#100",
360,
53,
Nearest,
"-1.4098657419642452e-29",
"-0x1.1df46a2529d39E-24#53",
Greater,
);
test(
"90.000000000000000000000000000808",
"0x5a.000000000000000000000040#100",
360,
53,
Floor,
"-1.4098657419642455e-29",
"-0x1.1df46a2529d3aE-24#53",
Less,
);
test(
"-90.000000000000000000000000000808",
"-0x5a.000000000000000000000040#100",
360,
53,
Nearest,
"-1.4098657419642452e-29",
"-0x1.1df46a2529d39E-24#53",
Greater,
);
test(
"269.99999999999999999999999999919",
"0x10d.ffffffffffffffffffffffc#100",
360,
53,
Nearest,
"-1.4098657419642452e-29",
"-0x1.1df46a2529d39E-24#53",
Greater,
);
test("1.0", "0x1.0#1", 8, 1, Nearest, "0.50", "0x0.8#1", Less);
test(
"1.0",
"0x1.0#1",
8,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
8,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"1.0",
"0x1.0#1",
8,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"1.0",
"0x1.0#1",
8,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test("1.0", "0x1.0#1", 8, 10, Down, "0.70703", "0x0.b50#10", Less);
test(
"1.0",
"0x1.0#1",
8,
10,
Up,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
8,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test(
"3.0", "0x3.0#2", 8, 1, Nearest, "-0.50", "-0x0.8#1", Greater,
);
test(
"3.0",
"0x3.0#2",
8,
10,
Nearest,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"-3.0",
"-0x3.0#2",
8,
10,
Nearest,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
8,
10,
Floor,
"-0.70801",
"-0x0.b54#10",
Less,
);
test(
"3.0",
"0x3.0#2",
8,
10,
Ceiling,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
8,
10,
Down,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test("3.0", "0x3.0#2", 8, 10, Up, "-0.70801", "-0x0.b54#10", Less);
test(
"3.0",
"0x3.0#2",
8,
53,
Nearest,
"-0.70710678118654757",
"-0x0.b504f333f9de68#53",
Less,
);
test(
"5.0", "0x5.0#3", 8, 1, Nearest, "-0.50", "-0x0.8#1", Greater,
);
test(
"5.0",
"0x5.0#3",
8,
10,
Nearest,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"-5.0",
"-0x5.0#3",
8,
10,
Nearest,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"5.0",
"0x5.0#3",
8,
10,
Floor,
"-0.70801",
"-0x0.b54#10",
Less,
);
test(
"5.0",
"0x5.0#3",
8,
10,
Ceiling,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"5.0",
"0x5.0#3",
8,
10,
Down,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test("5.0", "0x5.0#3", 8, 10, Up, "-0.70801", "-0x0.b54#10", Less);
test(
"5.0",
"0x5.0#3",
8,
53,
Nearest,
"-0.70710678118654757",
"-0x0.b504f333f9de68#53",
Less,
);
test("7.0", "0x7.0#3", 8, 1, Nearest, "0.50", "0x0.8#1", Less);
test(
"7.0",
"0x7.0#3",
8,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"-7.0",
"-0x7.0#3",
8,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"7.0",
"0x7.0#3",
8,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"7.0",
"0x7.0#3",
8,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test("7.0", "0x7.0#3", 8, 10, Down, "0.70703", "0x0.b50#10", Less);
test(
"7.0",
"0x7.0#3",
8,
10,
Up,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"7.0",
"0x7.0#3",
8,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test("9.00", "0x9.0#4", 8, 1, Nearest, "0.50", "0x0.8#1", Less);
test(
"9.00",
"0x9.0#4",
8,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"-9.00",
"-0x9.0#4",
8,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"9.00",
"0x9.0#4",
8,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"9.00",
"0x9.0#4",
8,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"9.00",
"0x9.0#4",
8,
10,
Down,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"9.00",
"0x9.0#4",
8,
10,
Up,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"9.00",
"0x9.0#4",
8,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test("1.0", "0x1.0#1", 12, 1, Nearest, "1.0", "0x1.0#1", Greater);
test(
"1.0",
"0x1.0#1",
12,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
12,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
12,
10,
Floor,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"1.0",
"0x1.0#1",
12,
10,
Ceiling,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
12,
10,
Down,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"1.0",
"0x1.0#1",
12,
10,
Up,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
12,
53,
Nearest,
"0.86602540378443860",
"0x0.ddb3d742c26550#53",
Less,
);
test("5.0", "0x5.0#3", 12, 1, Nearest, "-1.0", "-0x1.0#1", Less);
test(
"5.0",
"0x5.0#3",
12,
10,
Nearest,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"-5.0",
"-0x5.0#3",
12,
10,
Nearest,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"5.0",
"0x5.0#3",
12,
10,
Floor,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"5.0",
"0x5.0#3",
12,
10,
Ceiling,
"-0.86523",
"-0x0.dd8#10",
Greater,
);
test(
"5.0",
"0x5.0#3",
12,
10,
Down,
"-0.86523",
"-0x0.dd8#10",
Greater,
);
test(
"5.0",
"0x5.0#3",
12,
10,
Up,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"5.0",
"0x5.0#3",
12,
53,
Nearest,
"-0.86602540378443860",
"-0x0.ddb3d742c26550#53",
Greater,
);
test("7.0", "0x7.0#3", 12, 1, Nearest, "-1.0", "-0x1.0#1", Less);
test(
"7.0",
"0x7.0#3",
12,
10,
Nearest,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"-7.0",
"-0x7.0#3",
12,
10,
Nearest,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"7.0",
"0x7.0#3",
12,
10,
Floor,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"7.0",
"0x7.0#3",
12,
10,
Ceiling,
"-0.86523",
"-0x0.dd8#10",
Greater,
);
test(
"7.0",
"0x7.0#3",
12,
10,
Down,
"-0.86523",
"-0x0.dd8#10",
Greater,
);
test(
"7.0",
"0x7.0#3",
12,
10,
Up,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"7.0",
"0x7.0#3",
12,
53,
Nearest,
"-0.86602540378443860",
"-0x0.ddb3d742c26550#53",
Greater,
);
test("11.0", "0xb.0#4", 12, 1, Nearest, "1.0", "0x1.0#1", Greater);
test(
"11.0",
"0xb.0#4",
12,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"-11.0",
"-0xb.0#4",
12,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"11.0",
"0xb.0#4",
12,
10,
Floor,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"11.0",
"0xb.0#4",
12,
10,
Ceiling,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"11.0",
"0xb.0#4",
12,
10,
Down,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"11.0",
"0xb.0#4",
12,
10,
Up,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"11.0",
"0xb.0#4",
12,
53,
Nearest,
"0.86602540378443860",
"0x0.ddb3d742c26550#53",
Less,
);
test("1.0", "0x1.0#1", 5, 1, Nearest, "0.25", "0x0.4#1", Less);
test(
"1.0",
"0x1.0#1",
5,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"-1.0",
"-0x1.0#1",
5,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
5,
10,
Floor,
"0.30859",
"0x0.4f0#10",
Less,
);
test(
"1.0",
"0x1.0#1",
5,
10,
Ceiling,
"0.30908",
"0x0.4f2#10",
Greater,
);
test("1.0", "0x1.0#1", 5, 10, Down, "0.30859", "0x0.4f0#10", Less);
test(
"1.0",
"0x1.0#1",
5,
10,
Up,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
5,
53,
Nearest,
"0.30901699437494745",
"0x0.4f1bbcdcbfa540#53",
Greater,
);
test("2.0", "0x2.0#1", 5, 1, Nearest, "-1.0", "-0x1.0#1", Less);
test(
"2.0",
"0x2.0#1",
5,
10,
Nearest,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"-2.0",
"-0x2.0#1",
5,
10,
Nearest,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
5,
10,
Floor,
"-0.80957",
"-0x0.cf4#10",
Less,
);
test(
"2.0",
"0x2.0#1",
5,
10,
Ceiling,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
5,
10,
Down,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test("2.0", "0x2.0#1", 5, 10, Up, "-0.80957", "-0x0.cf4#10", Less);
test(
"2.0",
"0x2.0#1",
5,
53,
Nearest,
"-0.80901699437494745",
"-0x0.cf1bbcdcbfa540#53",
Less,
);
test("3.0", "0x3.0#2", 5, 1, Nearest, "-1.0", "-0x1.0#1", Less);
test(
"3.0",
"0x3.0#2",
5,
10,
Nearest,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"-3.0",
"-0x3.0#2",
5,
10,
Nearest,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
5,
10,
Floor,
"-0.80957",
"-0x0.cf4#10",
Less,
);
test(
"3.0",
"0x3.0#2",
5,
10,
Ceiling,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
5,
10,
Down,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test("3.0", "0x3.0#2", 5, 10, Up, "-0.80957", "-0x0.cf4#10", Less);
test(
"3.0",
"0x3.0#2",
5,
53,
Nearest,
"-0.80901699437494745",
"-0x0.cf1bbcdcbfa540#53",
Less,
);
test("4.0", "0x4.0#1", 5, 1, Nearest, "0.25", "0x0.4#1", Less);
test(
"4.0",
"0x4.0#1",
5,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"-4.0",
"-0x4.0#1",
5,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"4.0",
"0x4.0#1",
5,
10,
Floor,
"0.30859",
"0x0.4f0#10",
Less,
);
test(
"4.0",
"0x4.0#1",
5,
10,
Ceiling,
"0.30908",
"0x0.4f2#10",
Greater,
);
test("4.0", "0x4.0#1", 5, 10, Down, "0.30859", "0x0.4f0#10", Less);
test(
"4.0",
"0x4.0#1",
5,
10,
Up,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"4.0",
"0x4.0#1",
5,
53,
Nearest,
"0.30901699437494745",
"0x0.4f1bbcdcbfa540#53",
Greater,
);
test("6.0", "0x6.0#2", 5, 1, Nearest, "0.25", "0x0.4#1", Less);
test(
"6.0",
"0x6.0#2",
5,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"-6.0",
"-0x6.0#2",
5,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"6.0",
"0x6.0#2",
5,
10,
Floor,
"0.30859",
"0x0.4f0#10",
Less,
);
test(
"6.0",
"0x6.0#2",
5,
10,
Ceiling,
"0.30908",
"0x0.4f2#10",
Greater,
);
test("6.0", "0x6.0#2", 5, 10, Down, "0.30859", "0x0.4f0#10", Less);
test(
"6.0",
"0x6.0#2",
5,
10,
Up,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"6.0",
"0x6.0#2",
5,
53,
Nearest,
"0.30901699437494745",
"0x0.4f1bbcdcbfa540#53",
Greater,
);
test("1.0", "0x1.0#1", 10, 1, Nearest, "1.0", "0x1.0#1", Greater);
test(
"1.0",
"0x1.0#1",
10,
10,
Nearest,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"-1.0",
"-0x1.0#1",
10,
10,
Nearest,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"1.0",
"0x1.0#1",
10,
10,
Floor,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"1.0",
"0x1.0#1",
10,
10,
Ceiling,
"0.80957",
"0x0.cf4#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
10,
10,
Down,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"1.0",
"0x1.0#1",
10,
10,
Up,
"0.80957",
"0x0.cf4#10",
Greater,
);
test(
"1.0",
"0x1.0#1",
10,
53,
Nearest,
"0.80901699437494745",
"0x0.cf1bbcdcbfa540#53",
Greater,
);
test(
"3.0", "0x3.0#2", 10, 1, Nearest, "-0.25", "-0x0.4#1", Greater,
);
test(
"3.0",
"0x3.0#2",
10,
10,
Nearest,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"-3.0",
"-0x3.0#2",
10,
10,
Nearest,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"3.0",
"0x3.0#2",
10,
10,
Floor,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"3.0",
"0x3.0#2",
10,
10,
Ceiling,
"-0.30859",
"-0x0.4f0#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
10,
10,
Down,
"-0.30859",
"-0x0.4f0#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
10,
10,
Up,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"3.0",
"0x3.0#2",
10,
53,
Nearest,
"-0.30901699437494745",
"-0x0.4f1bbcdcbfa540#53",
Less,
);
test(
"7.0", "0x7.0#3", 10, 1, Nearest, "-0.25", "-0x0.4#1", Greater,
);
test(
"7.0",
"0x7.0#3",
10,
10,
Nearest,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"-7.0",
"-0x7.0#3",
10,
10,
Nearest,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"7.0",
"0x7.0#3",
10,
10,
Floor,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"7.0",
"0x7.0#3",
10,
10,
Ceiling,
"-0.30859",
"-0x0.4f0#10",
Greater,
);
test(
"7.0",
"0x7.0#3",
10,
10,
Down,
"-0.30859",
"-0x0.4f0#10",
Greater,
);
test(
"7.0",
"0x7.0#3",
10,
10,
Up,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"7.0",
"0x7.0#3",
10,
53,
Nearest,
"-0.30901699437494745",
"-0x0.4f1bbcdcbfa540#53",
Less,
);
test("9.00", "0x9.0#4", 10, 1, Nearest, "1.0", "0x1.0#1", Greater);
test(
"9.00",
"0x9.0#4",
10,
10,
Nearest,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"-9.00",
"-0x9.0#4",
10,
10,
Nearest,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"9.00",
"0x9.0#4",
10,
10,
Floor,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"9.00",
"0x9.0#4",
10,
10,
Ceiling,
"0.80957",
"0x0.cf4#10",
Greater,
);
test(
"9.00",
"0x9.0#4",
10,
10,
Down,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"9.00",
"0x9.0#4",
10,
10,
Up,
"0.80957",
"0x0.cf4#10",
Greater,
);
test(
"9.00",
"0x9.0#4",
10,
53,
Nearest,
"0.80901699437494745",
"0x0.cf1bbcdcbfa540#53",
Greater,
);
test("45.0", "0x2d.0#6", 360, 1, Nearest, "0.50", "0x0.8#1", Less);
test(
"45.0",
"0x2d.0#6",
360,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"-45.0",
"-0x2d.0#6",
360,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"45.0",
"0x2d.0#6",
360,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"45.0",
"0x2d.0#6",
360,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"45.0",
"0x2d.0#6",
360,
10,
Down,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"45.0",
"0x2d.0#6",
360,
10,
Up,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"45.0",
"0x2d.0#6",
360,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test(
"135.0", "0x87.0#8", 360, 1, Nearest, "-0.50", "-0x0.8#1", Greater,
);
test(
"135.0",
"0x87.0#8",
360,
10,
Nearest,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"-135.0",
"-0x87.0#8",
360,
10,
Nearest,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"135.0",
"0x87.0#8",
360,
10,
Floor,
"-0.70801",
"-0x0.b54#10",
Less,
);
test(
"135.0",
"0x87.0#8",
360,
10,
Ceiling,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"135.0",
"0x87.0#8",
360,
10,
Down,
"-0.70703",
"-0x0.b50#10",
Greater,
);
test(
"135.0",
"0x87.0#8",
360,
10,
Up,
"-0.70801",
"-0x0.b54#10",
Less,
);
test(
"135.0",
"0x87.0#8",
360,
53,
Nearest,
"-0.70710678118654757",
"-0x0.b504f333f9de68#53",
Less,
);
test(
"30.0", "0x1e.0#4", 360, 1, Nearest, "1.0", "0x1.0#1", Greater,
);
test(
"30.0",
"0x1e.0#4",
360,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"-30.0",
"-0x1e.0#4",
360,
10,
Nearest,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"30.0",
"0x1e.0#4",
360,
10,
Floor,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"30.0",
"0x1e.0#4",
360,
10,
Ceiling,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"30.0",
"0x1e.0#4",
360,
10,
Down,
"0.86523",
"0x0.dd8#10",
Less,
);
test(
"30.0",
"0x1e.0#4",
360,
10,
Up,
"0.86621",
"0x0.ddc#10",
Greater,
);
test(
"30.0",
"0x1e.0#4",
360,
53,
Nearest,
"0.86602540378443860",
"0x0.ddb3d742c26550#53",
Less,
);
test(
"150.0", "0x96.0#7", 360, 1, Nearest, "-1.0", "-0x1.0#1", Less,
);
test(
"150.0",
"0x96.0#7",
360,
10,
Nearest,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"-150.0",
"-0x96.0#7",
360,
10,
Nearest,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"150.0",
"0x96.0#7",
360,
10,
Floor,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"150.0",
"0x96.0#7",
360,
10,
Ceiling,
"-0.86523",
"-0x0.dd8#10",
Greater,
);
test(
"150.0",
"0x96.0#7",
360,
10,
Down,
"-0.86523",
"-0x0.dd8#10",
Greater,
);
test(
"150.0",
"0x96.0#7",
360,
10,
Up,
"-0.86621",
"-0x0.ddc#10",
Less,
);
test(
"150.0",
"0x96.0#7",
360,
53,
Nearest,
"-0.86602540378443860",
"-0x0.ddb3d742c26550#53",
Greater,
);
test("72.0", "0x48.0#4", 360, 1, Nearest, "0.25", "0x0.4#1", Less);
test(
"72.0",
"0x48.0#4",
360,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"-72.0",
"-0x48.0#4",
360,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"72.0",
"0x48.0#4",
360,
10,
Floor,
"0.30859",
"0x0.4f0#10",
Less,
);
test(
"72.0",
"0x48.0#4",
360,
10,
Ceiling,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"72.0",
"0x48.0#4",
360,
10,
Down,
"0.30859",
"0x0.4f0#10",
Less,
);
test(
"72.0",
"0x48.0#4",
360,
10,
Up,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"72.0",
"0x48.0#4",
360,
53,
Nearest,
"0.30901699437494745",
"0x0.4f1bbcdcbfa540#53",
Greater,
);
test(
"144.0",
"0x9.0E+1#4",
360,
1,
Nearest,
"-1.0",
"-0x1.0#1",
Less,
);
test(
"144.0",
"0x9.0E+1#4",
360,
10,
Nearest,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"-144.0",
"-0x9.0E+1#4",
360,
10,
Nearest,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"144.0",
"0x9.0E+1#4",
360,
10,
Floor,
"-0.80957",
"-0x0.cf4#10",
Less,
);
test(
"144.0",
"0x9.0E+1#4",
360,
10,
Ceiling,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"144.0",
"0x9.0E+1#4",
360,
10,
Down,
"-0.80859",
"-0x0.cf0#10",
Greater,
);
test(
"144.0",
"0x9.0E+1#4",
360,
10,
Up,
"-0.80957",
"-0x0.cf4#10",
Less,
);
test(
"144.0",
"0x9.0E+1#4",
360,
53,
Nearest,
"-0.80901699437494745",
"-0x0.cf1bbcdcbfa540#53",
Less,
);
test(
"36.0", "0x24.0#4", 360, 1, Nearest, "1.0", "0x1.0#1", Greater,
);
test(
"36.0",
"0x24.0#4",
360,
10,
Nearest,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"-36.0",
"-0x24.0#4",
360,
10,
Nearest,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"36.0",
"0x24.0#4",
360,
10,
Floor,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"36.0",
"0x24.0#4",
360,
10,
Ceiling,
"0.80957",
"0x0.cf4#10",
Greater,
);
test(
"36.0",
"0x24.0#4",
360,
10,
Down,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"36.0",
"0x24.0#4",
360,
10,
Up,
"0.80957",
"0x0.cf4#10",
Greater,
);
test(
"36.0",
"0x24.0#4",
360,
53,
Nearest,
"0.80901699437494745",
"0x0.cf1bbcdcbfa540#53",
Greater,
);
test(
"108.0", "0x6c.0#5", 360, 1, Nearest, "-0.25", "-0x0.4#1", Greater,
);
test(
"108.0",
"0x6c.0#5",
360,
10,
Nearest,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"-108.0",
"-0x6c.0#5",
360,
10,
Nearest,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"108.0",
"0x6c.0#5",
360,
10,
Floor,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"108.0",
"0x6c.0#5",
360,
10,
Ceiling,
"-0.30859",
"-0x0.4f0#10",
Greater,
);
test(
"108.0",
"0x6c.0#5",
360,
10,
Down,
"-0.30859",
"-0x0.4f0#10",
Greater,
);
test(
"108.0",
"0x6c.0#5",
360,
10,
Up,
"-0.30908",
"-0x0.4f2#10",
Less,
);
test(
"108.0",
"0x6c.0#5",
360,
53,
Nearest,
"-0.30901699437494745",
"-0x0.4f1bbcdcbfa540#53",
Less,
);
test("2.0", "0x2.0#1", 16, 1, Nearest, "0.50", "0x0.8#1", Less);
test(
"2.0",
"0x2.0#1",
16,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"-2.0",
"-0x2.0#1",
16,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"2.0",
"0x2.0#1",
16,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"2.0",
"0x2.0#1",
16,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
16,
10,
Down,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"2.0",
"0x2.0#1",
16,
10,
Up,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"2.0",
"0x2.0#1",
16,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test("3.0", "0x3.0#2", 24, 1, Nearest, "0.50", "0x0.8#1", Less);
test(
"3.0",
"0x3.0#2",
24,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"-3.0",
"-0x3.0#2",
24,
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"3.0",
"0x3.0#2",
24,
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"3.0",
"0x3.0#2",
24,
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
24,
10,
Down,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"3.0",
"0x3.0#2",
24,
10,
Up,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"3.0",
"0x3.0#2",
24,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test("4.0", "0x4.0#1", 20, 1, Nearest, "0.25", "0x0.4#1", Less);
test(
"4.0",
"0x4.0#1",
20,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"-4.0",
"-0x4.0#1",
20,
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"4.0",
"0x4.0#1",
20,
10,
Floor,
"0.30859",
"0x0.4f0#10",
Less,
);
test(
"4.0",
"0x4.0#1",
20,
10,
Ceiling,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"4.0",
"0x4.0#1",
20,
10,
Down,
"0.30859",
"0x0.4f0#10",
Less,
);
test(
"4.0",
"0x4.0#1",
20,
10,
Up,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"4.0",
"0x4.0#1",
20,
53,
Nearest,
"0.30901699437494745",
"0x0.4f1bbcdcbfa540#53",
Greater,
);
test("6.0", "0x6.0#2", 60, 1, Nearest, "1.0", "0x1.0#1", Greater);
test(
"6.0",
"0x6.0#2",
60,
10,
Nearest,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"-6.0",
"-0x6.0#2",
60,
10,
Nearest,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"6.0",
"0x6.0#2",
60,
10,
Floor,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"6.0",
"0x6.0#2",
60,
10,
Ceiling,
"0.80957",
"0x0.cf4#10",
Greater,
);
test(
"6.0",
"0x6.0#2",
60,
10,
Down,
"0.80859",
"0x0.cf0#10",
Less,
);
test(
"6.0",
"0x6.0#2",
60,
10,
Up,
"0.80957",
"0x0.cf4#10",
Greater,
);
test(
"6.0",
"0x6.0#2",
60,
53,
Nearest,
"0.80901699437494745",
"0x0.cf1bbcdcbfa540#53",
Greater,
);
}
#[test]
#[should_panic]
fn cos_with_period_prec_round_fail_1() {
Float::ONE.cos_with_period_prec_round(3, 0, Floor);
}
#[test]
#[should_panic]
fn cos_with_period_prec_round_fail_2() {
Float::ONE.cos_with_period_prec_round(5, 10, Exact);
}
#[test]
#[should_panic]
fn cos_with_period_prec_round_ref_fail() {
Float::ONE.cos_with_period_prec_round_ref(5, 10, Exact);
}
#[test]
#[should_panic]
fn cos_with_period_prec_fail() {
Float::ONE.cos_with_period_prec(3, 0);
}
#[test]
#[should_panic]
fn cos_with_period_round_fail() {
Float::ONE.cos_with_period_round(5, Exact);
}
#[allow(clippy::needless_pass_by_value)]
fn cos_with_period_prec_round_properties_helper(x: Float, u: u64, prec: u64, rm: RoundingMode) {
if rm == Exact {
let (c, o) = x.cos_with_period_prec_round_ref(u, prec, Nearest);
if o == Equal {
let (ce, oe) = x.cos_with_period_prec_round_ref(u, prec, Exact);
assert_eq!(ComparableFloatRef(&ce), ComparableFloatRef(&c));
assert_eq!(oe, Equal);
} else {
assert_panic!(x.cos_with_period_prec_round_ref(u, prec, Exact));
}
return;
}
let (c, o) = x.clone().cos_with_period_prec_round(u, prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.cos_with_period_prec_round_ref(u, 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.cos_with_period_prec_round_assign(u, prec, rm);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if let Ok(rrm) = rug_round_try_from_rounding_mode(rm)
&& u32::try_from(u).is_ok()
{
let (rug_c, rug_o) =
rug_cos_with_period_prec_round(&rug::Float::exact_from(&x), u, prec, rrm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
assert_eq!(c.is_nan(), u == 0 || !x.is_finite());
if !c.is_nan() {
assert!(c.le_abs(&1u32));
if c.is_normal() {
assert_eq!(c.get_prec(), Some(prec));
}
let (c_neg, o_neg) = (-&x).cos_with_period_prec_round(u, prec, rm);
assert_eq!(ComparableFloatRef(&c_neg), ComparableFloatRef(&c));
assert_eq!(o_neg, o);
if x.is_finite() && u != 0 {
let (shifted, os) =
x.add_prec_round_ref_val(Float::from(u), x.significant_bits() + 64, Nearest);
if os == Equal {
let (c_shifted, o_shifted) = shifted.cos_with_period_prec_round(u, prec, rm);
assert_eq!(ComparableFloatRef(&c_shifted), ComparableFloatRef(&c));
assert_eq!(o_shifted, o);
}
}
}
if o == Equal {
for rm in exhaustive_rounding_modes() {
let (s, oo) = x.cos_with_period_prec_round_ref(u, prec, rm);
assert_eq!(ComparableFloatRef(&s), ComparableFloatRef(&c));
assert_eq!(oo, Equal);
}
} else {
assert_panic!(x.cos_with_period_prec_round_ref(u, prec, Exact));
}
}
#[test]
fn cos_with_period_prec_round_properties() {
float_unsigned_unsigned_rounding_mode_quadruple_gen_var_15().test_properties(
|(x, u, prec, rm)| {
cos_with_period_prec_round_properties_helper(x, u, prec, rm);
},
);
float_unsigned_unsigned_rounding_mode_quadruple_gen_var_16().test_properties(
|(x, u, prec, rm)| {
cos_with_period_prec_round_properties_helper(x, u, prec, rm);
},
);
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::ZERO.cos_with_period_prec_round(4, prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::one_prec(prec)));
assert_eq!(o, Equal);
let (c, o) = Float::ONE.cos_with_period_prec_round(0, prec, rm);
assert!(c.is_nan());
assert_eq!(o, Equal);
for (k, expected) in [
(0u32, Float::one_prec(prec)),
(1, Float::ZERO),
(2, -Float::one_prec(prec)),
(3, Float::ZERO),
] {
let (c, o) = Float::from(k).cos_with_period_prec_round(4, prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(expected));
assert_eq!(o, Equal);
}
let half = Float::one_prec(prec) >> 1u32;
for (k, expected) in [(1u32, half.clone()), (2, -&half), (4, -&half), (5, half.clone())] {
let (c, o) = Float::from(k).cos_with_period_prec_round(6, prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(expected));
assert_eq!(o, Equal);
}
});
}
#[test]
fn cos_with_period_prec_properties() {
float_unsigned_unsigned_triple_gen_var_1::<u64, u64>().test_properties(|(x, u, prec)| {
let (c, o) = x.clone().cos_with_period_prec(u, prec);
assert!(c.is_valid());
let (c_alt, o_alt) = x.cos_with_period_prec_ref(u, prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = x.cos_with_period_prec_round_ref(u, prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut c_alt = x.clone();
let o_alt = c_alt.cos_with_period_prec_assign(u, prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if u32::try_from(u).is_ok() {
let (rug_c, rug_o) = rug_cos_with_period_prec(&rug::Float::exact_from(&x), u, prec);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
});
}
#[test]
fn cos_with_period_round_properties() {
float_unsigned_rounding_mode_triple_gen_var_38().test_properties(|(x, u, rm)| {
let (c, o) = x.clone().cos_with_period_round(u, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.cos_with_period_round_ref(u, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = x.cos_with_period_prec_round_ref(u, x.significant_bits(), rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut c_alt = x.clone();
let o_alt = c_alt.cos_with_period_round_assign(u, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
});
}
#[test]
fn cos_with_period_properties() {
float_unsigned_pair_gen_var_2::<u64>().test_properties(|(x, u)| {
let c = x.clone().cos_with_period(u);
assert!(c.is_valid());
let c_alt = x.cos_with_period_ref(u);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
let mut c_alt = x.clone();
c_alt.cos_with_period_assign(u);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
let (c_alt, _) = x.cos_with_period_prec_round_ref(u, x.significant_bits(), Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(
ComparableFloatRef(&(-&x).cos_with_period(u)),
ComparableFloatRef(&c)
);
});
}
#[test]
fn test_cos_with_period_rational_prec_round() {
let test = |s, u: u64, prec: u64, rm, out: &str, out_hex: &str, o_out: Ordering| {
let x = Rational::from_str(s).unwrap();
let (c, o) = Float::cos_with_period_rational_prec_round(x.clone(), u, 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) = Float::cos_with_period_rational_prec_round_ref(&x, u, prec, rm);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if rm == Nearest {
let (c_alt, o_alt) = Float::cos_with_period_rational_prec(x.clone(), u, prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = Float::cos_with_period_rational_prec_ref(&x, u, prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
}
};
test("0", 4, 1, Nearest, "1.0", "0x1.0#1", Equal);
test("0", 4, 10, Nearest, "1.0000", "0x1.000#10", Equal);
test("0", 4, 10, Floor, "1.0000", "0x1.000#10", Equal);
test("0", 4, 10, Ceiling, "1.0000", "0x1.000#10", Equal);
test("0", 4, 10, Exact, "1.0000", "0x1.000#10", Equal);
test(
"0",
4,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test("0", 0, 1, Nearest, "NaN", "NaN", Equal);
test("0", 0, 10, Nearest, "NaN", "NaN", Equal);
test("0", 0, 10, Floor, "NaN", "NaN", Equal);
test("0", 0, 10, Ceiling, "NaN", "NaN", Equal);
test("0", 0, 10, Exact, "NaN", "NaN", Equal);
test("0", 0, 53, Nearest, "NaN", "NaN", Equal);
test("1", 0, 1, Nearest, "NaN", "NaN", Equal);
test("1", 0, 10, Nearest, "NaN", "NaN", Equal);
test("1", 0, 10, Floor, "NaN", "NaN", Equal);
test("1", 0, 10, Ceiling, "NaN", "NaN", Equal);
test("1", 0, 10, Exact, "NaN", "NaN", Equal);
test("1", 0, 53, Nearest, "NaN", "NaN", Equal);
test("90", 360, 1, Nearest, "0.0", "0x0.0", Equal);
test("90", 360, 10, Nearest, "0.0", "0x0.0", Equal);
test("90", 360, 10, Floor, "0.0", "0x0.0", Equal);
test("90", 360, 10, Ceiling, "0.0", "0x0.0", Equal);
test("90", 360, 10, Exact, "0.0", "0x0.0", Equal);
test("90", 360, 53, Nearest, "0.0", "0x0.0", Equal);
test("180", 360, 1, Nearest, "-1.0", "-0x1.0#1", Equal);
test("180", 360, 10, Nearest, "-1.0000", "-0x1.000#10", Equal);
test("180", 360, 10, Floor, "-1.0000", "-0x1.000#10", Equal);
test("180", 360, 10, Ceiling, "-1.0000", "-0x1.000#10", Equal);
test("180", 360, 10, Exact, "-1.0000", "-0x1.000#10", Equal);
test(
"180",
360,
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test("270", 360, 1, Nearest, "0.0", "0x0.0", Equal);
test("270", 360, 10, Nearest, "0.0", "0x0.0", Equal);
test("270", 360, 10, Floor, "0.0", "0x0.0", Equal);
test("270", 360, 10, Ceiling, "0.0", "0x0.0", Equal);
test("270", 360, 10, Exact, "0.0", "0x0.0", Equal);
test("270", 360, 53, Nearest, "0.0", "0x0.0", Equal);
test("360", 360, 1, Nearest, "1.0", "0x1.0#1", Equal);
test("360", 360, 10, Nearest, "1.0000", "0x1.000#10", Equal);
test("360", 360, 10, Floor, "1.0000", "0x1.000#10", Equal);
test("360", 360, 10, Ceiling, "1.0000", "0x1.000#10", Equal);
test("360", 360, 10, Exact, "1.0000", "0x1.000#10", Equal);
test(
"360",
360,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test("450", 360, 1, Nearest, "0.0", "0x0.0", Equal);
test("450", 360, 10, Nearest, "0.0", "0x0.0", Equal);
test("450", 360, 10, Floor, "0.0", "0x0.0", Equal);
test("450", 360, 10, Ceiling, "0.0", "0x0.0", Equal);
test("450", 360, 10, Exact, "0.0", "0x0.0", Equal);
test("450", 360, 53, Nearest, "0.0", "0x0.0", Equal);
test("60", 360, 1, Nearest, "0.50", "0x0.8#1", Equal);
test("60", 360, 10, Nearest, "0.50000", "0x0.800#10", Equal);
test("60", 360, 10, Floor, "0.50000", "0x0.800#10", Equal);
test("60", 360, 10, Ceiling, "0.50000", "0x0.800#10", Equal);
test("60", 360, 10, Exact, "0.50000", "0x0.800#10", Equal);
test(
"60",
360,
53,
Nearest,
"0.50000000000000000",
"0x0.80000000000000#53",
Equal,
);
test("120", 360, 1, Nearest, "-0.50", "-0x0.8#1", Equal);
test("120", 360, 10, Nearest, "-0.50000", "-0x0.800#10", Equal);
test("120", 360, 10, Floor, "-0.50000", "-0x0.800#10", Equal);
test("120", 360, 10, Ceiling, "-0.50000", "-0x0.800#10", Equal);
test("120", 360, 10, Exact, "-0.50000", "-0x0.800#10", Equal);
test(
"120",
360,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test("240", 360, 1, Nearest, "-0.50", "-0x0.8#1", Equal);
test("240", 360, 10, Nearest, "-0.50000", "-0x0.800#10", Equal);
test("240", 360, 10, Floor, "-0.50000", "-0x0.800#10", Equal);
test("240", 360, 10, Ceiling, "-0.50000", "-0x0.800#10", Equal);
test("240", 360, 10, Exact, "-0.50000", "-0x0.800#10", Equal);
test(
"240",
360,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test("300", 360, 1, Nearest, "0.50", "0x0.8#1", Equal);
test("300", 360, 10, Nearest, "0.50000", "0x0.800#10", Equal);
test("300", 360, 10, Floor, "0.50000", "0x0.800#10", Equal);
test("300", 360, 10, Ceiling, "0.50000", "0x0.800#10", Equal);
test("300", 360, 10, Exact, "0.50000", "0x0.800#10", Equal);
test(
"300",
360,
53,
Nearest,
"0.50000000000000000",
"0x0.80000000000000#53",
Equal,
);
test("45", 360, 1, Nearest, "0.50", "0x0.8#1", Less);
test("45", 360, 10, Nearest, "0.70703", "0x0.b50#10", Less);
test("45", 360, 10, Floor, "0.70703", "0x0.b50#10", Less);
test("45", 360, 10, Ceiling, "0.70801", "0x0.b54#10", Greater);
test(
"45",
360,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test("135", 360, 1, Nearest, "-0.50", "-0x0.8#1", Greater);
test("135", 360, 10, Nearest, "-0.70703", "-0x0.b50#10", Greater);
test("135", 360, 10, Floor, "-0.70801", "-0x0.b54#10", Less);
test("135", 360, 10, Ceiling, "-0.70703", "-0x0.b50#10", Greater);
test(
"135",
360,
53,
Nearest,
"-0.70710678118654757",
"-0x0.b504f333f9de68#53",
Less,
);
test("30", 360, 1, Nearest, "1.0", "0x1.0#1", Greater);
test("30", 360, 10, Nearest, "0.86621", "0x0.ddc#10", Greater);
test("30", 360, 10, Floor, "0.86523", "0x0.dd8#10", Less);
test("30", 360, 10, Ceiling, "0.86621", "0x0.ddc#10", Greater);
test(
"30",
360,
53,
Nearest,
"0.86602540378443860",
"0x0.ddb3d742c26550#53",
Less,
);
test("150", 360, 1, Nearest, "-1.0", "-0x1.0#1", Less);
test("150", 360, 10, Nearest, "-0.86621", "-0x0.ddc#10", Less);
test("150", 360, 10, Floor, "-0.86621", "-0x0.ddc#10", Less);
test("150", 360, 10, Ceiling, "-0.86523", "-0x0.dd8#10", Greater);
test(
"150",
360,
53,
Nearest,
"-0.86602540378443860",
"-0x0.ddb3d742c26550#53",
Greater,
);
test("72", 360, 1, Nearest, "0.25", "0x0.4#1", Less);
test("72", 360, 10, Nearest, "0.30908", "0x0.4f2#10", Greater);
test("72", 360, 10, Floor, "0.30859", "0x0.4f0#10", Less);
test("72", 360, 10, Ceiling, "0.30908", "0x0.4f2#10", Greater);
test(
"72",
360,
53,
Nearest,
"0.30901699437494745",
"0x0.4f1bbcdcbfa540#53",
Greater,
);
test("144", 360, 1, Nearest, "-1.0", "-0x1.0#1", Less);
test("144", 360, 10, Nearest, "-0.80859", "-0x0.cf0#10", Greater);
test("144", 360, 10, Floor, "-0.80957", "-0x0.cf4#10", Less);
test("144", 360, 10, Ceiling, "-0.80859", "-0x0.cf0#10", Greater);
test(
"144",
360,
53,
Nearest,
"-0.80901699437494745",
"-0x0.cf1bbcdcbfa540#53",
Less,
);
test("36", 360, 1, Nearest, "1.0", "0x1.0#1", Greater);
test("36", 360, 10, Nearest, "0.80859", "0x0.cf0#10", Less);
test("36", 360, 10, Floor, "0.80859", "0x0.cf0#10", Less);
test("36", 360, 10, Ceiling, "0.80957", "0x0.cf4#10", Greater);
test(
"36",
360,
53,
Nearest,
"0.80901699437494745",
"0x0.cf1bbcdcbfa540#53",
Greater,
);
test("108", 360, 1, Nearest, "-0.25", "-0x0.4#1", Greater);
test("108", 360, 10, Nearest, "-0.30908", "-0x0.4f2#10", Less);
test("108", 360, 10, Floor, "-0.30908", "-0x0.4f2#10", Less);
test("108", 360, 10, Ceiling, "-0.30859", "-0x0.4f0#10", Greater);
test(
"108",
360,
53,
Nearest,
"-0.30901699437494745",
"-0x0.4f1bbcdcbfa540#53",
Less,
);
test("1/3", 1, 1, Nearest, "-0.50", "-0x0.8#1", Equal);
test("1/3", 1, 10, Nearest, "-0.50000", "-0x0.800#10", Equal);
test("1/3", 1, 10, Floor, "-0.50000", "-0x0.800#10", Equal);
test("1/3", 1, 10, Ceiling, "-0.50000", "-0x0.800#10", Equal);
test("1/3", 1, 10, Exact, "-0.50000", "-0x0.800#10", Equal);
test(
"1/3",
1,
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test("1/8", 1, 1, Nearest, "0.50", "0x0.8#1", Less);
test("1/8", 1, 10, Nearest, "0.70703", "0x0.b50#10", Less);
test("1/8", 1, 10, Floor, "0.70703", "0x0.b50#10", Less);
test("1/8", 1, 10, Ceiling, "0.70801", "0x0.b54#10", Greater);
test(
"1/8",
1,
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test("1/5", 1, 1, Nearest, "0.25", "0x0.4#1", Less);
test("1/5", 1, 10, Nearest, "0.30908", "0x0.4f2#10", Greater);
test("1/5", 1, 10, Floor, "0.30859", "0x0.4f0#10", Less);
test("1/5", 1, 10, Ceiling, "0.30908", "0x0.4f2#10", Greater);
test(
"1/5",
1,
53,
Nearest,
"0.30901699437494745",
"0x0.4f1bbcdcbfa540#53",
Greater,
);
test("-1/10", 1, 1, Nearest, "1.0", "0x1.0#1", Greater);
test("-1/10", 1, 10, Nearest, "0.80859", "0x0.cf0#10", Less);
test("-1/10", 1, 10, Floor, "0.80859", "0x0.cf0#10", Less);
test("-1/10", 1, 10, Ceiling, "0.80957", "0x0.cf4#10", Greater);
test(
"-1/10",
1,
53,
Nearest,
"0.80901699437494745",
"0x0.cf1bbcdcbfa540#53",
Greater,
);
test("1/7", 1, 1, Nearest, "0.50", "0x0.8#1", Less);
test("1/7", 1, 10, Nearest, "0.62305", "0x0.9f8#10", Less);
test("1/7", 1, 10, Floor, "0.62305", "0x0.9f8#10", Less);
test("1/7", 1, 10, Ceiling, "0.62402", "0x0.9fc#10", Greater);
test(
"1/7",
1,
53,
Nearest,
"0.62348980185873348",
"0x0.9f9d07145f6e88#53",
Less,
);
test("2/7", 1, 1, Nearest, "-0.25", "-0x0.4#1", Less);
test("2/7", 1, 10, Nearest, "-0.22241", "-0x0.38f#10", Greater);
test("2/7", 1, 10, Floor, "-0.22266", "-0x0.390#10", Less);
test("2/7", 1, 10, Ceiling, "-0.22241", "-0x0.38f#10", Greater);
test(
"2/7",
1,
53,
Nearest,
"-0.22252093395631439",
"-0x0.38f721c6048b04#53",
Greater,
);
test("-3/7", 1, 1, Nearest, "-1.0", "-0x1.0#1", Less);
test("-3/7", 1, 10, Nearest, "-0.90137", "-0x0.e6c#10", Less);
test("-3/7", 1, 10, Floor, "-0.90137", "-0x0.e6c#10", Less);
test("-3/7", 1, 10, Ceiling, "-0.90039", "-0x0.e68#10", Greater);
test(
"-3/7",
1,
53,
Nearest,
"-0.90096886790241915",
"-0x0.e6a5e54e5ae388#53",
Less,
);
test("22/7", 1, 1, Nearest, "0.50", "0x0.8#1", Less);
test("22/7", 1, 10, Nearest, "0.62305", "0x0.9f8#10", Less);
test("22/7", 1, 10, Floor, "0.62305", "0x0.9f8#10", Less);
test("22/7", 1, 10, Ceiling, "0.62402", "0x0.9fc#10", Greater);
test(
"22/7",
1,
53,
Nearest,
"0.62348980185873348",
"0x0.9f9d07145f6e88#53",
Less,
);
test("1/7", 3, 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1/7", 3, 10, Nearest, "0.95605", "0x0.f4c#10", Greater);
test("1/7", 3, 10, Floor, "0.95508", "0x0.f48#10", Less);
test("1/7", 3, 10, Ceiling, "0.95605", "0x0.f4c#10", Greater);
test(
"1/7",
3,
53,
Nearest,
"0.95557280578614068",
"0x0.f4a06b5dcc6628#53",
Less,
);
test("355/113", 360, 1, Nearest, "1.0", "0x1.0#1", Greater);
test("355/113", 360, 10, Nearest, "0.99805", "0x0.ff8#10", Less);
test("355/113", 360, 10, Floor, "0.99805", "0x0.ff8#10", Less);
test(
"355/113",
360,
10,
Ceiling,
"0.99902",
"0x0.ffc#10",
Greater,
);
test(
"355/113",
360,
53,
Nearest,
"0.99849714960870273",
"0x0.ff9d825ab7f600#53",
Greater,
);
test("1", 7, 1, Nearest, "0.50", "0x0.8#1", Less);
test("1", 7, 10, Nearest, "0.62305", "0x0.9f8#10", Less);
test("1", 7, 10, Floor, "0.62305", "0x0.9f8#10", Less);
test("1", 7, 10, Ceiling, "0.62402", "0x0.9fc#10", Greater);
test(
"1",
7,
53,
Nearest,
"0.62348980185873348",
"0x0.9f9d07145f6e88#53",
Less,
);
test("1000000", 7, 1, Nearest, "0.50", "0x0.8#1", Less);
test("1000000", 7, 10, Nearest, "0.62305", "0x0.9f8#10", Less);
test("1000000", 7, 10, Floor, "0.62305", "0x0.9f8#10", Less);
test("1000000", 7, 10, Ceiling, "0.62402", "0x0.9fc#10", Greater);
test(
"1000000",
7,
53,
Nearest,
"0.62348980185873348",
"0x0.9f9d07145f6e88#53",
Less,
);
test("1/1000000", 1, 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1/1000000", 1, 10, Nearest, "1.0000", "0x1.000#10", Greater);
test("1/1000000", 1, 10, Floor, "0.99902", "0x0.ffc#10", Less);
test("1/1000000", 1, 10, Ceiling, "1.0000", "0x1.000#10", Greater);
test(
"1/1000000",
1,
53,
Nearest,
"0.99999999998026079",
"0x0.ffffffffea4be8#53",
Less,
);
test(
"1/1000000000000000000000000000000",
1,
1,
Nearest,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1/1000000000000000000000000000000",
1,
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1000000000000000000000000000000",
1,
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1/1000000000000000000000000000000",
1,
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1/1000000000000000000000000000000",
1,
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"100000000000000000000000000000000000000001",
4,
1,
Nearest,
"0.0",
"0x0.0",
Equal,
);
test(
"100000000000000000000000000000000000000001",
4,
10,
Nearest,
"0.0",
"0x0.0",
Equal,
);
test(
"100000000000000000000000000000000000000001",
4,
10,
Floor,
"0.0",
"0x0.0",
Equal,
);
test(
"100000000000000000000000000000000000000001",
4,
10,
Ceiling,
"0.0",
"0x0.0",
Equal,
);
test(
"100000000000000000000000000000000000000001",
4,
10,
Exact,
"0.0",
"0x0.0",
Equal,
);
test(
"100000000000000000000000000000000000000001",
4,
53,
Nearest,
"0.0",
"0x0.0",
Equal,
);
test(
"111414603535684224740921180161/1237940039285380274899124224",
360,
53,
Nearest,
"-1.4098657419642452e-29",
"-0x1.1df46a2529d39E-24#53",
Greater,
);
test(
"111414603535684224740921180161/1237940039285380274899124224",
360,
53,
Floor,
"-1.4098657419642455e-29",
"-0x1.1df46a2529d3aE-24#53",
Less,
);
test(
"342265662061621938404109865451519/1267650600228229401496703205376",
360,
10,
Nearest,
"-1.3770e-32",
"-0x4.78E-27#10",
Less,
);
}
#[test]
#[should_panic]
fn cos_with_period_rational_prec_round_fail_1() {
Float::cos_with_period_rational_prec_round(Rational::ONE, 7, 0, Floor);
}
#[test]
#[should_panic]
fn cos_with_period_rational_prec_round_fail_2() {
Float::cos_with_period_rational_prec_round(Rational::ONE, 7, 10, Exact);
}
#[test]
#[should_panic]
fn cos_with_period_rational_prec_round_ref_fail() {
Float::cos_with_period_rational_prec_round_ref(&Rational::ONE, 7, 10, Exact);
}
#[test]
#[should_panic]
fn cos_with_period_rational_prec_fail() {
Float::cos_with_period_rational_prec(Rational::ONE, 7, 0);
}
#[allow(clippy::needless_pass_by_value)]
fn cos_with_period_rational_prec_round_properties_helper(
x: Rational,
u: u64,
prec: u64,
rm: RoundingMode,
) {
if rm == Exact {
let (c, o) = Float::cos_with_period_rational_prec_round_ref(&x, u, prec, Nearest);
if o == Equal {
let (ce, oe) = Float::cos_with_period_rational_prec_round_ref(&x, u, prec, Exact);
assert_eq!(ComparableFloatRef(&ce), ComparableFloatRef(&c));
assert_eq!(oe, Equal);
} else {
assert_panic!(Float::cos_with_period_rational_prec_round_ref(
&x, u, prec, Exact
));
}
return;
}
let (c, o) = Float::cos_with_period_rational_prec_round(x.clone(), u, prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = Float::cos_with_period_rational_prec_round_ref(&x, u, prec, rm);
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if o != Equal
&& let Ok(rrm) = rug_round_try_from_rounding_mode(rm)
&& u32::try_from(u).is_ok()
{
let (rug_c, rug_o) = rug_cos_with_period_rational_prec_round(&x, u, prec, rrm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
assert_eq!(c.is_nan(), u == 0);
if u != 0 {
assert!(c.le_abs(&1u32));
if c.is_normal() {
assert_eq!(c.get_prec(), Some(prec));
}
let (c_neg, o_neg) = Float::cos_with_period_rational_prec_round(-&x, u, prec, rm);
assert_eq!(ComparableFloatRef(&c_neg), ComparableFloatRef(&c));
assert_eq!(o_neg, o);
let (c_shifted, o_shifted) =
Float::cos_with_period_rational_prec_round(&x + Rational::from(u), u, prec, rm);
assert_eq!(ComparableFloatRef(&c_shifted), ComparableFloatRef(&c));
assert_eq!(o_shifted, o);
if let Ok(f) = Float::try_from(&x) {
let (c_alt, o_alt) = f.cos_with_period_prec_round(u, prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
}
}
if o == Equal {
for rm in exhaustive_rounding_modes() {
let (s, oo) = Float::cos_with_period_rational_prec_round_ref(&x, u, prec, rm);
assert_eq!(ComparableFloatRef(&s), ComparableFloatRef(&c));
assert_eq!(oo, Equal);
}
} else {
assert_panic!(Float::cos_with_period_rational_prec_round_ref(
&x, u, prec, Exact
));
}
}
#[test]
fn cos_with_period_rational_prec_round_properties() {
rational_unsigned_unsigned_rounding_mode_quadruple_gen_var_4().test_properties(
|(x, u, prec, rm)| {
cos_with_period_rational_prec_round_properties_helper(x, u, prec, rm);
},
);
unsigned_rounding_mode_pair_gen_var_3().test_properties(|(prec, rm)| {
let (c, o) = Float::cos_with_period_rational_prec_round(Rational::ZERO, 4, prec, rm);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::one_prec(prec)));
assert_eq!(o, Equal);
let (c, o) = Float::cos_with_period_rational_prec_round(Rational::ONE, 0, prec, rm);
assert!(c.is_nan());
assert_eq!(o, Equal);
for (s, expected) in [
("1/4", Float::ZERO),
("1/2", -Float::one_prec(prec)),
("3/4", Float::ZERO),
("1", Float::one_prec(prec)),
("1/6", Float::one_prec(prec) >> 1u32),
("1/3", -(Float::one_prec(prec) >> 1u32)),
] {
let (c, o) = Float::cos_with_period_rational_prec_round(
Rational::from_str(s).unwrap(),
1,
prec,
rm,
);
assert_eq!(ComparableFloat(c), ComparableFloat(expected));
assert_eq!(o, Equal);
}
});
}
#[test]
fn cos_with_period_rational_prec_properties() {
rational_unsigned_unsigned_rounding_mode_quadruple_gen_var_4().test_properties(
|(x, u, prec, _)| {
let (c, o) = Float::cos_with_period_rational_prec(x.clone(), u, prec);
assert!(c.is_valid());
let (c_alt, o_alt) = Float::cos_with_period_rational_prec_ref(&x, u, prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) =
Float::cos_with_period_rational_prec_round_ref(&x, u, prec, Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if o != Equal && u32::try_from(u).is_ok() {
let (rug_c, rug_o) = rug_cos_with_period_rational_prec(&x, u, prec);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
},
);
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_cos_with_period() {
fn test<T: PrimitiveFloat>(x: T, u: u64, out: T)
where
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
{
assert_eq!(
NiceFloat(primitive_float_cos_with_period(x, u)),
NiceFloat(out)
);
}
test::<f32>(f32::NAN, 360, f32::NAN);
test::<f32>(f32::INFINITY, 360, f32::NAN);
test::<f32>(f32::NEGATIVE_INFINITY, 360, f32::NAN);
test::<f32>(1.0, 0, f32::NAN);
test::<f32>(0.0, 360, 1.0);
test::<f32>(-0.0, 360, 1.0);
test::<f32>(90.0, 360, 0.0);
test::<f32>(180.0, 360, -1.0);
test::<f32>(270.0, 360, 0.0);
test::<f32>(360.0, 360, 1.0);
test::<f32>(60.0, 360, 0.5);
test::<f32>(120.0, 360, -0.5);
test::<f32>(45.0, 360, core::f32::consts::FRAC_1_SQRT_2);
test::<f32>(30.0, 360, 0.8660254);
test::<f32>(72.0, 360, 0.309017);
test::<f32>(36.0, 360, 0.809017);
test::<f32>(1.0, 7, 0.6234898);
test::<f32>(-1.0, 7, 0.6234898);
test::<f32>(2.0, 7, -0.22252093);
test::<f32>(1.0, 360, 0.9998477);
test::<f32>(100.0, 360, -0.17364818);
test::<f32>(1.0e10, 360, 0.17364818);
test::<f32>(1.0e30, 7, 0.6234898);
test::<f32>(1.0e-30, 7, 1.0);
test::<f32>(3.4028235e38, 360, 1.0);
test::<f32>(0.5, 1, -1.0);
test::<f32>(0.25, 1, 0.0);
test::<f32>(0.1, 1, 0.809017);
test::<f64>(f64::NAN, 360, f64::NAN);
test::<f64>(f64::INFINITY, 360, f64::NAN);
test::<f64>(f64::NEGATIVE_INFINITY, 360, f64::NAN);
test::<f64>(1.0, 0, f64::NAN);
test::<f64>(0.0, 360, 1.0);
test::<f64>(-0.0, 360, 1.0);
test::<f64>(90.0, 360, 0.0);
test::<f64>(180.0, 360, -1.0);
test::<f64>(270.0, 360, 0.0);
test::<f64>(360.0, 360, 1.0);
test::<f64>(60.0, 360, 0.5);
test::<f64>(120.0, 360, -0.5);
test::<f64>(45.0, 360, core::f64::consts::FRAC_1_SQRT_2);
test::<f64>(30.0, 360, 0.8660254037844386);
test::<f64>(72.0, 360, 0.30901699437494745);
test::<f64>(36.0, 360, 0.8090169943749475);
test::<f64>(1.0, 7, 0.6234898018587335);
test::<f64>(-1.0, 7, 0.6234898018587335);
test::<f64>(2.0, 7, -0.2225209339563144);
test::<f64>(1.0, 360, 0.9998476951563913);
test::<f64>(100.0, 360, -0.17364817766693036);
test::<f64>(1.0e10, 360, 0.17364817766693036);
test::<f64>(1.0e100, 7, -0.2225209339563144);
test::<f64>(1.0e-100, 7, 1.0);
test::<f64>(1.7976931348623157e308, 360, -0.6156614753256583);
test::<f64>(0.5, 1, -1.0);
test::<f64>(0.25, 1, 0.0);
test::<f64>(0.1, 1, 0.8090169943749475);
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_cos_with_period_rational() {
fn test<T: PrimitiveFloat>(s: &str, u: u64, 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_cos_with_period_rational::<T>(&x, u)),
NiceFloat(out)
);
}
test::<f32>("0", 360, 1.0);
test::<f32>("1", 0, f32::NAN);
test::<f32>("90", 360, 0.0);
test::<f32>("180", 360, -1.0);
test::<f32>("60", 360, 0.5);
test::<f32>("45", 360, core::f32::consts::FRAC_1_SQRT_2);
test::<f32>("36", 360, 0.809017);
test::<f32>("1/3", 1, -0.5);
test::<f32>("1/8", 1, core::f32::consts::FRAC_1_SQRT_2);
test::<f32>("1/5", 1, 0.309017);
test::<f32>("1/7", 1, 0.6234898);
test::<f32>("-2/7", 1, -0.22252093);
test::<f32>("22/7", 1, 0.6234898);
test::<f32>("1", 7, 0.6234898);
test::<f32>("1000000", 7, 0.6234898);
test::<f32>("1/1000000", 1, 1.0);
test::<f32>("355/113", 360, 0.9984971);
test::<f64>("0", 360, 1.0);
test::<f64>("1", 0, f64::NAN);
test::<f64>("90", 360, 0.0);
test::<f64>("180", 360, -1.0);
test::<f64>("60", 360, 0.5);
test::<f64>("45", 360, core::f64::consts::FRAC_1_SQRT_2);
test::<f64>("36", 360, 0.8090169943749475);
test::<f64>("1/3", 1, -0.5);
test::<f64>("1/8", 1, core::f64::consts::FRAC_1_SQRT_2);
test::<f64>("1/5", 1, 0.30901699437494745);
test::<f64>("1/7", 1, 0.6234898018587335);
test::<f64>("-2/7", 1, -0.2225209339563144);
test::<f64>("22/7", 1, 0.6234898018587335);
test::<f64>("1", 7, 0.6234898018587335);
test::<f64>("1000000", 7, 0.6234898018587335);
test::<f64>("1/1000000", 1, 0.9999999999802608);
test::<f64>("355/113", 360, 0.9984971496087027);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_cos_with_period_properties_helper<T: PrimitiveFloat>()
where
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
{
primitive_float_unsigned_pair_gen_var_1::<T, u64>().test_properties(|(x, u)| {
let c = primitive_float_cos_with_period(x, u);
assert_eq!(c.is_nan(), u == 0);
if u != 0 {
assert!(c >= T::NEGATIVE_ONE && c <= T::ONE);
assert_eq!(
NiceFloat(primitive_float_cos_with_period(-x, u)),
NiceFloat(c)
);
let rug_c = rug_cos_with_period_prec(
&rug::Float::exact_from(&Float::from(x)),
u,
T::MANTISSA_WIDTH + 1,
)
.0;
let rug_c: T = T::exact_from(&<Float as From<&rug::Float>>::from(&rug_c));
assert_eq!(NiceFloat(rug_c), NiceFloat(c));
}
});
primitive_float_gen::<T>().test_properties(|x| {
assert_eq!(
primitive_float_cos_with_period(x, 7).is_nan(),
!x.is_finite()
);
});
}
#[test]
fn primitive_float_cos_with_period_properties() {
apply_fn_to_primitive_floats!(primitive_float_cos_with_period_properties_helper);
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_cos_with_period_rational_properties_helper<T: PrimitiveFloat>()
where
Float: From<T> + PartialOrd<T>,
Rational: ExactFrom<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
{
rational_unsigned_pair_gen_var_1::<u64>().test_properties(|(x, u)| {
let c = primitive_float_cos_with_period_rational::<T>(&x, u);
assert_eq!(c.is_nan(), u == 0);
if u != 0 {
assert!(c >= T::NEGATIVE_ONE && c <= T::ONE);
assert_eq!(
NiceFloat(primitive_float_cos_with_period_rational::<T>(&-&x, u)),
NiceFloat(c)
);
assert_eq!(
NiceFloat(primitive_float_cos_with_period_rational::<T>(
&(&x + Rational::from(u)),
u
)),
NiceFloat(c)
);
let (c_float, o) =
Float::cos_with_period_rational_prec_ref(&x, u, T::MANTISSA_WIDTH + 1);
assert_eq!(NiceFloat(T::exact_from(&c_float)), NiceFloat(c));
if o != Equal {
let rug_c = rug_cos_with_period_rational_prec(&x, u, T::MANTISSA_WIDTH + 1).0;
let rug_c: T = T::exact_from(&<Float as From<&rug::Float>>::from(&rug_c));
assert_eq!(NiceFloat(rug_c), NiceFloat(c));
}
}
});
primitive_float_unsigned_pair_gen_var_1::<T, u64>().test_properties(|(x, u)| {
assert_eq!(
NiceFloat(primitive_float_cos_with_period_rational::<T>(
&Rational::exact_from(x),
u
)),
NiceFloat(primitive_float_cos_with_period(x, u))
);
});
}
#[test]
fn primitive_float_cos_with_period_rational_properties() {
apply_fn_to_primitive_floats!(primitive_float_cos_with_period_rational_properties_helper);
}
#[test]
fn test_cos_with_period_underflow() {
let min_positive = Float::one_prec(10) >> (1u64 << 30);
let eps = Rational::power_of_2(-((1i64 << 30) + 70));
let above =
Float::from_rational_prec_round(Rational::from(90u32) + &eps, (1u64 << 30) + 78, Exact).0;
let below =
Float::from_rational_prec_round(Rational::from(90u32) - eps, (1u64 << 30) + 78, Exact).0;
let (c, o) = above.cos_with_period_prec_round_ref(360, 10, Nearest);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::NEGATIVE_ZERO));
assert_eq!(o, Greater);
let (c, o) = above.cos_with_period_prec_round_ref(360, 10, Floor);
assert_eq!(ComparableFloat(c), ComparableFloat(-&min_positive));
assert_eq!(o, Less);
let (c, o) = below.cos_with_period_prec_round_ref(360, 10, Ceiling);
assert_eq!(ComparableFloatRef(&c), ComparableFloatRef(&min_positive));
assert_eq!(o, Greater);
let (c, o) = below.cos_with_period_prec_round_ref(360, 10, Down);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::ZERO));
assert_eq!(o, Less);
}
#[test]
fn test_cos_with_period_rational_underflow() {
let min_positive = Float::one_prec(10) >> (1u64 << 30);
let eps = Rational::power_of_2(-((1i64 << 30) + 70));
let above = Rational::from(90u32) + &eps;
let below = Rational::from(90u32) - eps;
let (c, o) = Float::cos_with_period_rational_prec_round_ref(&above, 360, 10, Nearest);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::NEGATIVE_ZERO));
assert_eq!(o, Greater);
let (c, o) = Float::cos_with_period_rational_prec_round_ref(&above, 360, 10, Floor);
assert_eq!(ComparableFloat(c), ComparableFloat(-&min_positive));
assert_eq!(o, Less);
let (c, o) = Float::cos_with_period_rational_prec_round_ref(&below, 360, 10, Ceiling);
assert_eq!(ComparableFloatRef(&c), ComparableFloatRef(&min_positive));
assert_eq!(o, Greater);
let (c, o) = Float::cos_with_period_rational_prec_round_ref(&below, 360, 10, Down);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::ZERO));
assert_eq!(o, Less);
let tiny = Rational::power_of_2(-((1i64 << 30) + 70)) / Rational::from(3u32);
let x = Rational::from_unsigneds(1u32, 4u32) + tiny;
let (c, o) = Float::cos_with_period_rational_prec_round_ref(&x, 1, 10, Nearest);
assert_eq!(ComparableFloat(c), ComparableFloat(Float::NEGATIVE_ZERO));
assert_eq!(o, Greater);
}
#[test]
fn test_cos_with_period_near_turn() {
let eps = Rational::power_of_2(-((1i64 << 30) + 70));
let p = (1u64 << 30) + 80;
let below_turn = Float::from_rational_prec_round(Rational::from(360u32) - &eps, p, Exact).0;
let neg = -(Float::one_prec(10) >> (1u64 << 30));
let below_two_turns =
Float::from_rational_prec_round(Rational::from(720u32) - &eps, p, Exact).0;
let one = Float::one_prec(10);
for x in [&below_turn, &neg, &below_two_turns] {
let (c, o) = x.cos_with_period_prec_round_ref(360, 10, Nearest);
assert_eq!(ComparableFloatRef(&c), ComparableFloatRef(&one));
assert_eq!(o, Greater);
let (c, o) = x.cos_with_period_prec_round_ref(360, 10, Floor);
assert_eq!(c.to_string(), "0.99902");
assert_eq!(o, Less);
let (c, o) = x.cos_with_period_prec_round_ref(360, 10, Ceiling);
assert_eq!(ComparableFloatRef(&c), ComparableFloatRef(&one));
assert_eq!(o, Greater);
}
for x in [
Rational::from(360u32) - &eps,
-&eps,
Rational::from(720u32) - &eps,
-Rational::from(360u32) - &eps,
-(&eps / Rational::from(3u32)),
] {
let (c, o) = Float::cos_with_period_rational_prec_round_ref(&x, 360, 10, Nearest);
assert_eq!(ComparableFloatRef(&c), ComparableFloatRef(&one));
assert_eq!(o, Greater);
let (c, o) = Float::cos_with_period_rational_prec_round_ref(&x, 360, 10, Floor);
assert_eq!(c.to_string(), "0.99902");
assert_eq!(o, Less);
}
let x = Rational::from(360u32) - Rational::power_of_2(-100i64);
let (c, o) = Float::cos_with_period_rational_prec_round_ref(&x, 360, 10, Floor);
assert_eq!(c.to_string(), "0.99902");
assert_eq!(o, Less);
}
#[test]
fn test_cos_pi_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().cos_pi_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.cos_pi_prec_round_ref(prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut c_alt = x.clone();
let o_alt = c_alt.cos_pi_prec_round_assign(prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if rm == Nearest {
let (c_alt, o_alt) = x.cos_pi_prec_ref(prec);
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_cos_pi_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("NaN", "NaN", 10, Nearest, "NaN", "NaN", Equal);
test("NaN", "NaN", 10, Floor, "NaN", "NaN", Equal);
test("NaN", "NaN", 10, Ceiling, "NaN", "NaN", Equal);
test("NaN", "NaN", 10, Exact, "NaN", "NaN", Equal);
test("NaN", "NaN", 53, Nearest, "NaN", "NaN", Equal);
test("Infinity", "Infinity", 1, Nearest, "NaN", "NaN", Equal);
test("Infinity", "Infinity", 10, Nearest, "NaN", "NaN", Equal);
test("Infinity", "Infinity", 10, Floor, "NaN", "NaN", Equal);
test("Infinity", "Infinity", 10, Ceiling, "NaN", "NaN", Equal);
test("Infinity", "Infinity", 10, Exact, "NaN", "NaN", Equal);
test("Infinity", "Infinity", 53, Nearest, "NaN", "NaN", 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("0.0", "0x0.0", 10, Floor, "1.0000", "0x1.000#10", Equal);
test("0.0", "0x0.0", 10, Ceiling, "1.0000", "0x1.000#10", Equal);
test("0.0", "0x0.0", 10, Exact, "1.0000", "0x1.000#10", Equal);
test(
"0.0",
"0x0.0",
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test("0.50", "0x0.8#1", 1, Nearest, "0.0", "0x0.0", Equal);
test("0.50", "0x0.8#1", 10, Nearest, "0.0", "0x0.0", Equal);
test("0.50", "0x0.8#1", 10, Floor, "0.0", "0x0.0", Equal);
test("0.50", "0x0.8#1", 10, Ceiling, "0.0", "0x0.0", Equal);
test("0.50", "0x0.8#1", 10, Exact, "0.0", "0x0.0", Equal);
test("0.50", "0x0.8#1", 53, Nearest, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 1, Nearest, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 10, Nearest, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 10, Floor, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 10, Ceiling, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 10, Exact, "0.0", "0x0.0", Equal);
test("1.5", "0x1.8#2", 53, Nearest, "0.0", "0x0.0", Equal);
test("1.0", "0x1.0#1", 1, Nearest, "-1.0", "-0x1.0#1", Equal);
test(
"1.0",
"0x1.0#1",
10,
Nearest,
"-1.0000",
"-0x1.000#10",
Equal,
);
test("1.0", "0x1.0#1", 10, Floor, "-1.0000", "-0x1.000#10", Equal);
test(
"1.0",
"0x1.0#1",
10,
Ceiling,
"-1.0000",
"-0x1.000#10",
Equal,
);
test("1.0", "0x1.0#1", 10, Exact, "-1.0000", "-0x1.000#10", Equal);
test(
"1.0",
"0x1.0#1",
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test("2.0", "0x2.0#1", 1, Nearest, "1.0", "0x1.0#1", Equal);
test("2.0", "0x2.0#1", 10, Nearest, "1.0000", "0x1.000#10", Equal);
test("2.0", "0x2.0#1", 10, Floor, "1.0000", "0x1.000#10", Equal);
test("2.0", "0x2.0#1", 10, Ceiling, "1.0000", "0x1.000#10", Equal);
test("2.0", "0x2.0#1", 10, Exact, "1.0000", "0x1.000#10", Equal);
test(
"2.0",
"0x2.0#1",
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test("0.25", "0x0.4#1", 1, Nearest, "0.50", "0x0.8#1", Less);
test(
"0.25",
"0x0.4#1",
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test("0.25", "0x0.4#1", 10, Floor, "0.70703", "0x0.b50#10", Less);
test(
"0.25",
"0x0.4#1",
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"0.25",
"0x0.4#1",
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test(
"0.10000000000000001",
"0x0.1999999999999a#52",
1,
Nearest,
"1.0",
"0x1.0#1",
Greater,
);
test(
"0.10000000000000001",
"0x0.1999999999999a#52",
10,
Nearest,
"0.95117",
"0x0.f38#10",
Greater,
);
test(
"0.10000000000000001",
"0x0.1999999999999a#52",
10,
Floor,
"0.95020",
"0x0.f34#10",
Less,
);
test(
"0.10000000000000001",
"0x0.1999999999999a#52",
10,
Ceiling,
"0.95117",
"0x0.f38#10",
Greater,
);
test(
"0.10000000000000001",
"0x0.1999999999999a#52",
53,
Nearest,
"0.95105651629515353",
"0x0.f378709a22a7f8#53",
Less,
);
test(
"0.40000000000000002",
"0x0.66666666666668#52",
1,
Nearest,
"0.25",
"0x0.4#1",
Less,
);
test(
"0.40000000000000002",
"0x0.66666666666668#52",
10,
Nearest,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"0.40000000000000002",
"0x0.66666666666668#52",
10,
Floor,
"0.30859",
"0x0.4f0#10",
Less,
);
test(
"0.40000000000000002",
"0x0.66666666666668#52",
10,
Ceiling,
"0.30908",
"0x0.4f2#10",
Greater,
);
test(
"0.40000000000000002",
"0x0.66666666666668#52",
53,
Nearest,
"0.30901699437494734",
"0x0.4f1bbcdcbfa538#53",
Less,
);
test("100.2", "0x64.4#9", 1, Nearest, "0.50", "0x0.8#1", Less);
test(
"100.2",
"0x64.4#9",
10,
Nearest,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"100.2",
"0x64.4#9",
10,
Floor,
"0.70703",
"0x0.b50#10",
Less,
);
test(
"100.2",
"0x64.4#9",
10,
Ceiling,
"0.70801",
"0x0.b54#10",
Greater,
);
test(
"100.2",
"0x64.4#9",
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
1,
Nearest,
"1.0",
"0x1.0#1",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
10,
Nearest,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
10,
Floor,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
10,
Exact,
"1.0000",
"0x1.000#10",
Equal,
);
test(
"1.00000000e10",
"0x2.540be4E+8#24",
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test(
"1.000000000000000e-30",
"0x1.4484bfeebc2aE-25#48",
1,
Nearest,
"1.0",
"0x1.0#1",
Greater,
);
test(
"1.000000000000000e-30",
"0x1.4484bfeebc2aE-25#48",
10,
Nearest,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.000000000000000e-30",
"0x1.4484bfeebc2aE-25#48",
10,
Floor,
"0.99902",
"0x0.ffc#10",
Less,
);
test(
"1.000000000000000e-30",
"0x1.4484bfeebc2aE-25#48",
10,
Ceiling,
"1.0000",
"0x1.000#10",
Greater,
);
test(
"1.000000000000000e-30",
"0x1.4484bfeebc2aE-25#48",
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Greater,
);
test(
"-0.10000000000000001",
"-0x0.1999999999999a#52",
1,
Nearest,
"1.0",
"0x1.0#1",
Greater,
);
test(
"-0.10000000000000001",
"-0x0.1999999999999a#52",
10,
Nearest,
"0.95117",
"0x0.f38#10",
Greater,
);
test(
"-0.10000000000000001",
"-0x0.1999999999999a#52",
10,
Floor,
"0.95020",
"0x0.f34#10",
Less,
);
test(
"-0.10000000000000001",
"-0x0.1999999999999a#52",
10,
Ceiling,
"0.95117",
"0x0.f38#10",
Greater,
);
test(
"-0.10000000000000001",
"-0x0.1999999999999a#52",
53,
Nearest,
"0.95105651629515353",
"0x0.f378709a22a7f8#53",
Less,
);
}
#[test]
fn test_cos_pi_rational_prec_round() {
let test = |s, prec: u64, rm, out: &str, out_hex: &str, o_out: Ordering| {
let x = Rational::from_str(s).unwrap();
let (c, o) = Float::cos_pi_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, o_out);
let (c_alt, o_alt) = Float::cos_pi_rational_prec_round_ref(&x, prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if rm == Nearest {
let (c_alt, o_alt) = Float::cos_pi_rational_prec(x.clone(), prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = Float::cos_pi_rational_prec_ref(&x, prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
}
};
test("0", 1, Nearest, "1.0", "0x1.0#1", Equal);
test("0", 10, Nearest, "1.0000", "0x1.000#10", Equal);
test("0", 10, Floor, "1.0000", "0x1.000#10", Equal);
test("0", 10, Ceiling, "1.0000", "0x1.000#10", Equal);
test("0", 10, Exact, "1.0000", "0x1.000#10", Equal);
test(
"0",
53,
Nearest,
"1.0000000000000000",
"0x1.0000000000000#53",
Equal,
);
test("1/2", 1, Nearest, "0.0", "0x0.0", Equal);
test("1/2", 10, Nearest, "0.0", "0x0.0", Equal);
test("1/2", 10, Floor, "0.0", "0x0.0", Equal);
test("1/2", 10, Ceiling, "0.0", "0x0.0", Equal);
test("1/2", 10, Exact, "0.0", "0x0.0", Equal);
test("1/2", 53, Nearest, "0.0", "0x0.0", Equal);
test("1", 1, Nearest, "-1.0", "-0x1.0#1", Equal);
test("1", 10, Nearest, "-1.0000", "-0x1.000#10", Equal);
test("1", 10, Floor, "-1.0000", "-0x1.000#10", Equal);
test("1", 10, Ceiling, "-1.0000", "-0x1.000#10", Equal);
test("1", 10, Exact, "-1.0000", "-0x1.000#10", Equal);
test(
"1",
53,
Nearest,
"-1.0000000000000000",
"-0x1.0000000000000#53",
Equal,
);
test("1/3", 1, Nearest, "0.50", "0x0.8#1", Equal);
test("1/3", 10, Nearest, "0.50000", "0x0.800#10", Equal);
test("1/3", 10, Floor, "0.50000", "0x0.800#10", Equal);
test("1/3", 10, Ceiling, "0.50000", "0x0.800#10", Equal);
test("1/3", 10, Exact, "0.50000", "0x0.800#10", Equal);
test(
"1/3",
53,
Nearest,
"0.50000000000000000",
"0x0.80000000000000#53",
Equal,
);
test("2/3", 1, Nearest, "-0.50", "-0x0.8#1", Equal);
test("2/3", 10, Nearest, "-0.50000", "-0x0.800#10", Equal);
test("2/3", 10, Floor, "-0.50000", "-0x0.800#10", Equal);
test("2/3", 10, Ceiling, "-0.50000", "-0x0.800#10", Equal);
test("2/3", 10, Exact, "-0.50000", "-0x0.800#10", Equal);
test(
"2/3",
53,
Nearest,
"-0.50000000000000000",
"-0x0.80000000000000#53",
Equal,
);
test("1/4", 1, Nearest, "0.50", "0x0.8#1", Less);
test("1/4", 10, Nearest, "0.70703", "0x0.b50#10", Less);
test("1/4", 10, Floor, "0.70703", "0x0.b50#10", Less);
test("1/4", 10, Ceiling, "0.70801", "0x0.b54#10", Greater);
test(
"1/4",
53,
Nearest,
"0.70710678118654757",
"0x0.b504f333f9de68#53",
Greater,
);
test("1/6", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1/6", 10, Nearest, "0.86621", "0x0.ddc#10", Greater);
test("1/6", 10, Floor, "0.86523", "0x0.dd8#10", Less);
test("1/6", 10, Ceiling, "0.86621", "0x0.ddc#10", Greater);
test(
"1/6",
53,
Nearest,
"0.86602540378443860",
"0x0.ddb3d742c26550#53",
Less,
);
test("1/5", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1/5", 10, Nearest, "0.80859", "0x0.cf0#10", Less);
test("1/5", 10, Floor, "0.80859", "0x0.cf0#10", Less);
test("1/5", 10, Ceiling, "0.80957", "0x0.cf4#10", Greater);
test(
"1/5",
53,
Nearest,
"0.80901699437494745",
"0x0.cf1bbcdcbfa540#53",
Greater,
);
test("2/5", 1, Nearest, "0.25", "0x0.4#1", Less);
test("2/5", 10, Nearest, "0.30908", "0x0.4f2#10", Greater);
test("2/5", 10, Floor, "0.30859", "0x0.4f0#10", Less);
test("2/5", 10, Ceiling, "0.30908", "0x0.4f2#10", Greater);
test(
"2/5",
53,
Nearest,
"0.30901699437494745",
"0x0.4f1bbcdcbfa540#53",
Greater,
);
test("1/7", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1/7", 10, Nearest, "0.90137", "0x0.e6c#10", Greater);
test("1/7", 10, Floor, "0.90039", "0x0.e68#10", Less);
test("1/7", 10, Ceiling, "0.90137", "0x0.e6c#10", Greater);
test(
"1/7",
53,
Nearest,
"0.90096886790241915",
"0x0.e6a5e54e5ae388#53",
Greater,
);
test("-3/7", 1, Nearest, "0.25", "0x0.4#1", Greater);
test("-3/7", 10, Nearest, "0.22241", "0x0.38f#10", Less);
test("-3/7", 10, Floor, "0.22241", "0x0.38f#10", Less);
test("-3/7", 10, Ceiling, "0.22266", "0x0.390#10", Greater);
test(
"-3/7",
53,
Nearest,
"0.22252093395631439",
"0x0.38f721c6048b04#53",
Less,
);
test("22/7", 1, Nearest, "-1.0", "-0x1.0#1", Less);
test("22/7", 10, Nearest, "-0.90137", "-0x0.e6c#10", Less);
test("22/7", 10, Floor, "-0.90137", "-0x0.e6c#10", Less);
test("22/7", 10, Ceiling, "-0.90039", "-0x0.e68#10", Greater);
test(
"22/7",
53,
Nearest,
"-0.90096886790241915",
"-0x0.e6a5e54e5ae388#53",
Less,
);
test("1/1000000", 1, Nearest, "1.0", "0x1.0#1", Greater);
test("1/1000000", 10, Nearest, "1.0000", "0x1.000#10", 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",
53,
Nearest,
"0.99999999999506517",
"0x0.fffffffffa92f8#53",
Less,
);
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_cos_pi() {
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_cos_pi(x)), NiceFloat(out));
}
test::<f32>(f32::NAN, f32::NAN);
test::<f32>(0.5, 0.0);
test::<f32>(1.0, -1.0);
test::<f32>(0.25, core::f32::consts::FRAC_1_SQRT_2);
test::<f32>(0.1, 0.95105654);
test::<f32>(-0.1, 0.95105654);
test::<f32>(100.25, core::f32::consts::FRAC_1_SQRT_2);
test::<f32>(1.0e10, 1.0);
test::<f64>(f64::NAN, f64::NAN);
test::<f64>(0.5, 0.0);
test::<f64>(1.0, -1.0);
test::<f64>(0.25, core::f64::consts::FRAC_1_SQRT_2);
test::<f64>(0.1, 0.9510565162951535);
test::<f64>(-0.1, 0.9510565162951535);
test::<f64>(100.25, core::f64::consts::FRAC_1_SQRT_2);
test::<f64>(1.0e10, 1.0);
}
#[test]
#[allow(clippy::type_repetition_in_bounds)]
fn test_primitive_float_cos_pi_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_cos_pi_rational::<T>(&x)),
NiceFloat(out)
);
}
test::<f32>("1/2", 0.0);
test::<f32>("1/3", 0.5);
test::<f32>("1/4", core::f32::consts::FRAC_1_SQRT_2);
test::<f32>("1/7", 0.90096885);
test::<f32>("-3/7", 0.22252093);
test::<f32>("22/7", -0.90096885);
test::<f64>("1/2", 0.0);
test::<f64>("1/3", 0.5);
test::<f64>("1/4", core::f64::consts::FRAC_1_SQRT_2);
test::<f64>("1/7", 0.9009688679024191);
test::<f64>("-3/7", 0.2225209339563144);
test::<f64>("22/7", -0.9009688679024191);
}
#[test]
#[should_panic]
fn cos_pi_prec_round_fail_1() {
Float::from(0.1f64).cos_pi_prec_round(0, Floor);
}
#[test]
#[should_panic]
fn cos_pi_prec_round_fail_2() {
Float::from(0.1f64).cos_pi_prec_round(10, Exact);
}
#[test]
#[should_panic]
fn cos_pi_rational_prec_round_fail() {
Float::cos_pi_rational_prec_round(Rational::from_unsigneds(1u8, 7), 10, Exact);
}
#[test]
fn cos_pi_properties() {
let exact_ok = |x: &Float, prec: u64, rm: RoundingMode| {
rm != Exact || x.cos_with_period_prec_round_ref(2, prec, Nearest).1 == Equal
};
float_unsigned_rounding_mode_triple_gen_var_36().test_properties(|(x, prec, rm)| {
if !exact_ok(&x, prec, rm) {
assert_panic!(x.cos_pi_prec_round_ref(prec, Exact));
return;
}
let (c, o) = x.clone().cos_pi_prec_round(prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.cos_with_period_prec_round_ref(2, prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = x.cos_pi_prec_round_ref(prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut c_alt = x.clone();
let o_alt = c_alt.cos_pi_prec_round_assign(prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if let Ok(rrm) = rug_round_try_from_rounding_mode(rm) {
let (rug_c, rug_o) = rug_cos_pi_prec_round(&rug::Float::exact_from(&x), prec, rrm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
});
float_unsigned_rounding_mode_triple_gen_var_37().test_properties(|(x, prec, rm)| {
if !exact_ok(&x, prec, rm) {
return;
}
let (c, o) = x.cos_pi_prec_round_ref(prec, rm);
let (c_alt, o_alt) = x.cos_with_period_prec_round_ref(2, prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
});
float_unsigned_pair_gen_var_1().test_properties(|(x, prec)| {
let (c, o) = x.clone().cos_pi_prec(prec);
let (c_alt, o_alt) = x.cos_with_period_prec_ref(2, prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = x.cos_pi_prec_ref(prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut c_alt = x.clone();
let o_alt = c_alt.cos_pi_prec_assign(prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
});
float_rounding_mode_pair_gen_var_47().test_properties(|(x, rm)| {
if !exact_ok(&x, x.significant_bits(), rm) {
return;
}
let (c, o) = x.clone().cos_pi_round(rm);
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = x.cos_with_period_round_ref(2, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = x.cos_pi_round_ref(rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let mut c_alt = x.clone();
let o_alt = c_alt.cos_pi_round_assign(rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
});
rational_unsigned_rounding_mode_triple_gen_var_10().test_properties(|(x, prec, rm)| {
if rm == Exact && Float::cos_with_period_rational_prec_ref(&x, 2, prec).1 != Equal {
assert_panic!(Float::cos_pi_rational_prec_round_ref(&x, prec, Exact));
return;
}
let (c, o) = Float::cos_pi_rational_prec_round(x.clone(), prec, rm);
assert!(c.is_valid());
assert_rounding_ordering_consistent(&c, rm, o);
let (c_alt, o_alt) = Float::cos_with_period_rational_prec_round_ref(&x, 2, prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = Float::cos_pi_rational_prec_round_ref(&x, prec, rm);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
if o != Equal
&& let Ok(rrm) = rug_round_try_from_rounding_mode(rm)
{
let (rug_c, rug_o) = rug_cos_pi_rational_prec_round(&x, prec, rrm);
assert_eq!(
ComparableFloatRef(&Float::from(&rug_c)),
ComparableFloatRef(&c)
);
assert_eq!(rug_o, o);
}
});
rational_unsigned_pair_gen_var_3().test_properties(|(x, prec)| {
let (c, o) = Float::cos_pi_rational_prec(x.clone(), prec);
let (c_alt, o_alt) = Float::cos_with_period_rational_prec_ref(&x, 2, prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
let (c_alt, o_alt) = Float::cos_pi_rational_prec_ref(&x, prec);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
assert_eq!(o_alt, o);
});
float_gen().test_properties(|x| {
let c = x.clone().cos_pi();
assert!(c.is_valid());
let c_alt = x.cos_pi_ref();
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
let mut c_alt = x.clone();
c_alt.cos_pi_assign();
assert!(c_alt.is_valid());
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
let c_alt = x.cos_with_period_ref(2);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
let (c_alt, _) = x.cos_pi_prec_round_ref(x.significant_bits(), Nearest);
assert_eq!(ComparableFloatRef(&c_alt), ComparableFloatRef(&c));
});
}
#[allow(clippy::type_repetition_in_bounds)]
fn primitive_float_cos_pi_properties_helper<T: PrimitiveFloat>()
where
Float: From<T> + PartialOrd<T>,
Rational: ExactFrom<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
{
primitive_float_gen::<T>().test_properties(|x| {
assert_eq!(
NiceFloat(primitive_float_cos_pi(x)),
NiceFloat(primitive_float_cos_with_period(x, 2))
);
});
rational_gen().test_properties(|x| {
assert_eq!(
NiceFloat(primitive_float_cos_pi_rational::<T>(&x)),
NiceFloat(primitive_float_cos_with_period_rational::<T>(&x, 2))
);
});
}
#[test]
fn primitive_float_cos_pi_properties() {
apply_fn_to_primitive_floats!(primitive_float_cos_pi_properties_helper);
}