Skip to main content

malachite_float/float/arithmetic/
csc.rs

1// Copyright © 2026 Mikhail Hogrefe
2//
3// Uses code adopted from the GNU MPFR Library.
4//
5//      Copyright © 2005-2025 Free Software Foundation, Inc.
6//
7//      Contributed by the Pascaline and Caramba projects, INRIA.
8//
9// This file is part of Malachite.
10//
11// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
12// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
13// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
14
15// Port of MPFR's cosecant. `mpfr_csc` (`csc.c`) instantiates the generic reciprocal template
16// (`gen_inverse.h`) with the sine: the sine is taken at the working precision, rounded toward zero,
17// its reciprocal is rounded to nearest, and the result is certified with two bits of slack, inside
18// a Ziv loop. The cosecant never underflows, since its magnitude is at least 1, but it overflows
19// for an input within 2^(-2^30) of a multiple of pi, which MPFR, computing inside a temporarily
20// extended exponent range, never sees; a reciprocal at the top of the range is decided from an
21// exact bracket instead. MPFR's shortcut for a tiny input, where csc x is 1/x + x/6 + O(x^3), is
22// kept: there the Ziv loop could never certify a reciprocal that is exactly representable.
23
24use crate::InnerFloat::{Finite, Infinity, NaN, Zero};
25use crate::float::arithmetic::cos::{phi_minus_1_prec_round, signed_constant, sin_bound};
26use crate::float::arithmetic::round_near_x::round_near_reciprocal;
27use crate::float::arithmetic::sec::doubled;
28use crate::float::arithmetic::sin::{sin_rational_helper, sin_turns_helper};
29use crate::float::arithmetic::tan::{reciprocal_ziv_loop, round_bracket_signed};
30use crate::{Float, emulate_float_to_float_fn, emulate_rational_to_float_fn};
31use core::cmp::Ordering::{self, Equal};
32use core::cmp::max;
33use malachite_base::num::arithmetic::traits::{Abs, Csc, CscAssign, Mod, Reciprocal};
34use malachite_base::num::basic::floats::PrimitiveFloat;
35use malachite_base::num::basic::integers::PrimitiveInt;
36use malachite_base::num::basic::traits::{
37    Infinity as InfinityTrait, NaN as NaNTrait, NegativeInfinity, One,
38};
39use malachite_base::num::comparison::traits::PartialOrdAbs;
40use malachite_base::num::conversion::traits::{ExactFrom, RoundingFrom};
41use malachite_base::num::logic::traits::SignificantBits;
42use malachite_base::rounding_modes::RoundingMode::{self, *};
43use malachite_nz::integer::Integer;
44use malachite_q::Rational;
45
46// This is mpfr_csc from csc.c, MPFR 4.2.2, with the bracket path for results near the top of the
47// exponent range.
48fn csc_prec_round_normal_ref(x: &Float, prec: u64, rm: RoundingMode) -> (Float, Ordering) {
49    assert_ne!(rm, Exact, "Inexact csc");
50    let exp_x = i64::from(x.get_exponent().unwrap());
51    // ACTION_TINY from csc.c: EXP(x) <= -2 max(PREC(x), PREC(y)). There csc x = 1/x + x/6 + ...,
52    // and |csc x - 1/x| <= 0.2 for |x| <= 1, with the correction sharing the sign of 1/x, so that
53    // the cosecant lies just beyond 1/x.
54    let n = i64::exact_from(max(x.get_prec().unwrap(), prec));
55    if exp_x <= -(n << 1) {
56        return round_near_reciprocal(x, true, prec, rm);
57    }
58    reciprocal_ziv_loop(prec, rm, |m| x.sin_prec_round_ref(m, Down).0)
59}
60
61// csc x for a tiny nonzero `Rational` x, bracketed by inverting a bracket on the sine: `sin_bound`
62// pins sin x from both sides at a growing working precision, and the reciprocals of those bounds
63// bracket the cosecant until the rounding is unambiguous (the cosecant of a nonzero rational is
64// transcendental, so it eventually is). The general path cannot settle such an x: there csc x is
65// 1/x + x/6 + ..., with the correction far below the resolution of any reciprocal of a rounded
66// sine, so the Ziv loop would have to raise the working precision to about twice the input's
67// exponent, which is unbounded below the `Float` exponent range.
68fn csc_rational_tiny(
69    x: &Rational,
70    ax: &Rational,
71    prec: u64,
72    rm: RoundingMode,
73) -> (Float, Ordering) {
74    let mut w = prec + 64;
75    loop {
76        // sin x lies in [s_lo, s_hi], so its reciprocal lies in [1/s_hi, 1/s_lo]
77        let s_lo = sin_bound(ax, w, false);
78        let s_hi = sin_bound(ax, w, true);
79        if let Some(result) =
80            round_bracket_signed(x, s_hi.reciprocal(), s_lo.reciprocal(), prec, rm)
81        {
82            return result;
83        }
84        w <<= 1;
85    }
86}
87
88// Computes csc(x) for a nonzero `Rational` x, rounded to precision `prec` with rounding mode `rm`.
89// (csc(0) = infinity is handled by the caller.) The cosecant of a nonzero rational is
90// transcendental, so the result is never exactly representable and `rm` must not be `Exact`.
91//
92// This is the `Float` algorithm with the sine taken from `sin_rational_helper`, which rounds the
93// input once and handles both a tiny x and an x too large to be a `Float`, and with a direct
94// bracket for a tiny input, standing in for MPFR's shortcut there.
95pub(crate) fn csc_rational_helper(x: &Rational, prec: u64, rm: RoundingMode) -> (Float, Ordering) {
96    assert_ne!(rm, Exact, "Inexact csc");
97    let exp_x = x.floor_log_base_2_abs() + 1; // the MPFR-style exponent of x
98    // Below this the reciprocal of a rounded sine can never be certified: the correction x/6 is
99    // smaller than any ulp the loop could reach without raising the working precision to about
100    // twice the input's exponent.
101    if exp_x < 0 && -(exp_x << 2) > i64::exact_from(prec) + 3 {
102        return csc_rational_tiny(x, &x.abs(), prec, rm);
103    }
104    reciprocal_ziv_loop(prec, rm, |m| sin_rational_helper(x, m, Down).0)
105}
106
107// The exact and closed-form values of csc(2 pi q) at the eighths, twelfths, and twentieths of a
108// turn, where the sine is 0, ±1, ±1/2, ±sqrt(2)/2, ±sqrt(3)/2, ±phi/2, or ±(phi - 1)/2.
109// Returns `None` when q is none of them, or when only an inexact value is available and `rm` is
110// `Exact`.
111fn csc_turns_special_case(q: &Rational, prec: u64, rm: RoundingMode) -> Option<(Float, Ordering)> {
112    let d = q.denominator_ref();
113    if *d > 20u32 {
114        return None;
115    }
116    let d = u64::exact_from(d);
117    // the angle in units of 1/d of a turn (the numerator of a `Rational` is unsigned, so the sign
118    // is restored before reducing modulo d)
119    let n = u64::exact_from(
120        &Integer::from_sign_and_abs_ref(*q >= 0u32, q.numerator_ref()).mod_op(Integer::from(d)),
121    );
122    // the cosecant, like the sine, is negative in the second half of the turn
123    let negative = n > d >> 1;
124    match d {
125        // The poles at 0 and 180°, where the sine is a zero carrying the sign of q, so its
126        // reciprocal is an infinity with that sign; that keeps the cosecant odd.
127        1 | 2 => Some((
128            if *q < 0u32 {
129                Float::NEGATIVE_INFINITY
130            } else {
131                Float::INFINITY
132            },
133            Equal,
134        )),
135        // csc(90°) = 1, csc(270°) = -1
136        4 => Some((
137            if negative {
138                -Float::one_prec(prec)
139            } else {
140                Float::one_prec(prec)
141            },
142            Equal,
143        )),
144        // csc(30°) = csc(150°) = 2, csc(210°) = csc(330°) = -2
145        12 => Some((
146            if negative {
147                -(Float::one_prec(prec) << 1u32)
148            } else {
149                Float::one_prec(prec) << 1u32
150            },
151            Equal,
152        )),
153        _ if rm == Exact => None,
154        // csc(60°) = csc(120°) = 2 sqrt(3)/3, and its negative at 240° and 300°. Doubling is
155        // exact, so the correctly rounded constant stays correctly rounded.
156        3 | 6 => Some(doubled(signed_constant(
157            Float::sqrt_3_over_3_prec_round,
158            negative,
159            prec,
160            rm,
161        ))),
162        // csc(45°) = csc(135°) = sqrt(2), and its negative at 225° and 315°
163        8 => Some(signed_constant(
164            Float::sqrt_2_prec_round,
165            negative,
166            prec,
167            rm,
168        )),
169        // The sine is (phi - 1)/2 at 18° and phi/2 at 54°, so the cosecant is 2 phi and 2(phi -
170        // 1) there, and their negatives in the second half of the turn.
171        20 => Some(if n == 1 || n == 9 || n == 11 || n == 19 {
172            doubled(signed_constant(Float::phi_prec_round, negative, prec, rm))
173        } else {
174            doubled(signed_constant(phi_minus_1_prec_round, negative, prec, rm))
175        }),
176        _ => None,
177    }
178}
179
180// Computes csc(2 pi q) for a nonzero `Rational` fraction of a turn q in (-1, 1), rounded to
181// precision `prec` with rounding mode `rm`. This is the `Rational` counterpart of
182// `csc_with_period_prec_round_normal_ref`, with the same structure: the closed-form cases and a Ziv
183// loop around the reciprocal of `sin_turns_helper`. `rm` may be `Exact` only in the exact cases.
184//
185// The tiny-input shortcut the radian version needs has no counterpart here. In turns the angle 2 pi
186// q is never a `Float`, so by Niven's theorem the sine of a q past the closed-form cases is
187// irrational and its reciprocal is never exactly representable, which is what stalls the radian
188// loop. An angle below the exponent range makes the sine underflow to zero, and the bracket reads
189// that as an overflow, which is what it is.
190fn csc_turns_helper(q: &Rational, prec: u64, rm: RoundingMode) -> (Float, Ordering) {
191    let exp_q = q.floor_log_base_2_abs() + 1;
192    // The special cases need |q| >= 1/20
193    if exp_q >= -4
194        && let Some(result) = csc_turns_special_case(q, prec, rm)
195    {
196        return result;
197    }
198    // Only the exact cases can be rounded exactly
199    assert_ne!(rm, Exact, "Inexact csc_with_period");
200    reciprocal_ziv_loop(prec, rm, |m| sin_turns_helper(q, m, Down).0)
201}
202
203// Computes csc(2 pi x/u) for a finite nonzero `Float` x and a nonzero u. This has no MPFR
204// counterpart; it is `csc` with the sine taken in uths of a turn, which reduces the argument
205// exactly rather than modulo an approximation of 2 pi, and so reaches the exact and closed-form
206// cases that the radian version cannot see. MPFR's shortcut for a tiny input is not needed here:
207// the angle 2 pi x/u is never a `Float`, so the reciprocal of the rounded sine is not stuck on an
208// exactly representable value, and an angle below the exponent range makes the sine underflow,
209// which the bracket reads as an overflow.
210fn csc_with_period_prec_round_normal_ref(
211    x: &Float,
212    u: u64,
213    prec: u64,
214    rm: RoundingMode,
215) -> (Float, Ordering) {
216    // Range reduction, as in `tan_with_period`: the argument is already reduced if |x| < u.
217    let xr;
218    let xp = if x.lt_abs(&u) {
219        x
220    } else {
221        // xr = x mod u, with the sign of x, exactly
222        let p = i64::exact_from(x.get_prec().unwrap()) - i64::from(x.get_exponent().unwrap());
223        let (r, o) =
224            x.rem_unsigned_prec_round_ref(u, u64::WIDTH + u64::exact_from(max(p, 0)), Exact);
225        assert_eq!(o, Equal);
226        if r == 0u32 {
227            // x is a multiple of u, so the sine is a zero with the sign of x and the cosecant is an
228            // infinity with that sign
229            return (
230                if *x < 0u32 {
231                    Float::NEGATIVE_INFINITY
232                } else {
233                    Float::INFINITY
234                },
235                Equal,
236            );
237        }
238        xr = r;
239        &xr
240    };
241    // now |xp/u| < 1
242    let exp_x = i64::from(xp.get_exponent().unwrap());
243    // The special cases need |x/u| >= 1/20, so the exponent test skips the `Rational` construction
244    // for the small x that would make it expensive (a tiny x has a huge power-of-2 denominator).
245    if exp_x >= i64::exact_from(u.significant_bits()) - 5
246        && let Some(result) =
247            csc_turns_special_case(&(Rational::exact_from(xp) / Rational::from(u)), prec, rm)
248    {
249        return result;
250    }
251    // Only the exact cases can be rounded exactly
252    assert_ne!(rm, Exact, "Inexact csc_with_period");
253    reciprocal_ziv_loop(prec, rm, |m| {
254        xp.sin_with_period_prec_round_ref(u, m, Down).0
255    })
256}
257
258impl Float {
259    /// Computes $\csc x$, the cosecant of a [`Float`], rounding the result to the specified
260    /// precision and with the specified rounding mode. The [`Float`] is taken by value. An
261    /// [`Ordering`] is also returned, indicating whether the rounded cosecant is less than, equal
262    /// to, or greater than the exact cosecant. Although `NaN`s are not comparable to any [`Float`],
263    /// whenever this function returns a `NaN` it also returns `Equal`.
264    ///
265    /// See [`RoundingMode`] for a description of the possible rounding modes.
266    ///
267    /// $$
268    /// f(x,p,m) = \csc x+\varepsilon.
269    /// $$
270    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
271    /// - If $x$ is finite and $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc
272    ///   x|\rfloor-p+1}$.
273    /// - If $x$ is finite and $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc
274    ///   x|\rfloor-p}$.
275    ///
276    /// If the output has a precision, it is `prec`.
277    ///
278    /// Special cases:
279    /// - $f(\text{NaN},p,m)=\text{NaN}$
280    /// - $f(\pm\infty,p,m)=\text{NaN}$
281    /// - $f(\pm0.0,p,m)=\pm\infty$
282    ///
283    /// Overflow:
284    /// - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is `Ceiling`, `Up`, or `Nearest`, $\infty$ is
285    ///   returned instead.
286    /// - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is `Floor` or `Down`, $(1-(1/2)^p)2^{2^{30}-1}$ is
287    ///   returned instead.
288    /// - If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is `Floor`, `Up`, or `Nearest`, $-\infty$ is
289    ///   returned instead.
290    /// - If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is `Ceiling` or `Down`, $-(1-(1/2)^p)2^{2^{30}-1}$
291    ///   is returned instead.
292    /// - If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is `Nearest`, $0.0$ is returned instead.
293    /// - If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is `Nearest`, $-0.0$ is returned instead.
294    ///
295    /// Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within
296    /// $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of
297    /// precision, or an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond
298    /// the largest finite [`Float`].
299    ///
300    /// If you know you'll be using `Nearest`, consider using [`Float::csc_prec`] instead. If you
301    /// know that your target precision is the precision of the input, consider using
302    /// [`Float::csc_round`] instead. If both of these things are true, consider using
303    /// [`Float::csc`] instead.
304    ///
305    /// # Worst-case complexity
306    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
307    ///
308    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
309    ///
310    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is
311    /// `self.significant_bits()`, and $e$ is the exponent of `self` (0 if `self` has no exponent or
312    /// a negative one): the cosine at working precision $n$, summed by binary splitting of the
313    /// Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$
314    /// the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a
315    /// remainder of the $m$-bit input. Unlike most functions, `csc` therefore gets slower as the
316    /// magnitude of its input grows, not just as the precision does.
317    ///
318    /// # Panics
319    /// Panics if `rm` is `Exact`, since the cosecant of a finite nonzero [`Float`] is never exactly
320    /// representable, or if `prec` is zero.
321    ///
322    /// # Examples
323    /// ```
324    /// use malachite_base::rounding_modes::RoundingMode::*;
325    /// use malachite_float::Float;
326    /// use std::cmp::Ordering::*;
327    ///
328    /// let (c, o) = Float::from_unsigned_prec(1u32, 100)
329    ///     .0
330    ///     .csc_prec_round(5, Floor);
331    /// assert_eq!(c.to_string(), "1.19");
332    /// assert_eq!(o, Less);
333    ///
334    /// let (c, o) = Float::from_unsigned_prec(1u32, 100)
335    ///     .0
336    ///     .csc_prec_round(5, Ceiling);
337    /// assert_eq!(c.to_string(), "1.25");
338    /// assert_eq!(o, Greater);
339    ///
340    /// let (c, o) = Float::from_unsigned_prec(1u32, 100)
341    ///     .0
342    ///     .csc_prec_round(5, Nearest);
343    /// assert_eq!(c.to_string(), "1.19");
344    /// assert_eq!(o, Less);
345    ///
346    /// let (c, o) = Float::from_unsigned_prec(1u32, 100)
347    ///     .0
348    ///     .csc_prec_round(20, Floor);
349    /// assert_eq!(c.to_string(), "1.1883945");
350    /// assert_eq!(o, Less);
351    ///
352    /// let (c, o) = Float::from_unsigned_prec(1u32, 100)
353    ///     .0
354    ///     .csc_prec_round(20, Ceiling);
355    /// assert_eq!(c.to_string(), "1.1883965");
356    /// assert_eq!(o, Greater);
357    ///
358    /// let (c, o) = Float::from_unsigned_prec(1u32, 100)
359    ///     .0
360    ///     .csc_prec_round(20, Nearest);
361    /// assert_eq!(c.to_string(), "1.1883945");
362    /// assert_eq!(o, Less);
363    /// ```
364    #[inline]
365    pub fn csc_prec_round(self, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
366        self.csc_prec_round_ref(prec, rm)
367    }
368
369    /// Computes $\csc x$, the cosecant of a [`Float`], rounding the result to the specified
370    /// precision and with the specified rounding mode. The [`Float`] is taken by reference. An
371    /// [`Ordering`] is also returned, indicating whether the rounded cosecant is less than, equal
372    /// to, or greater than the exact cosecant. Although `NaN`s are not comparable to any [`Float`],
373    /// whenever this function returns a `NaN` it also returns `Equal`.
374    ///
375    /// See [`RoundingMode`] for a description of the possible rounding modes.
376    ///
377    /// $$
378    /// f(x,p,m) = \csc x+\varepsilon.
379    /// $$
380    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
381    /// - If $x$ is finite and $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc
382    ///   x|\rfloor-p+1}$.
383    /// - If $x$ is finite and $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc
384    ///   x|\rfloor-p}$.
385    ///
386    /// If the output has a precision, it is `prec`.
387    ///
388    /// Special cases:
389    /// - $f(\text{NaN},p,m)=\text{NaN}$
390    /// - $f(\pm\infty,p,m)=\text{NaN}$
391    /// - $f(\pm0.0,p,m)=\pm\infty$
392    ///
393    /// Overflow:
394    /// - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is `Ceiling`, `Up`, or `Nearest`, $\infty$ is
395    ///   returned instead.
396    /// - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is `Floor` or `Down`, $(1-(1/2)^p)2^{2^{30}-1}$ is
397    ///   returned instead.
398    /// - If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is `Floor`, `Up`, or `Nearest`, $-\infty$ is
399    ///   returned instead.
400    /// - If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is `Ceiling` or `Down`, $-(1-(1/2)^p)2^{2^{30}-1}$
401    ///   is returned instead.
402    /// - If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is `Nearest`, $0.0$ is returned instead.
403    /// - If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is `Nearest`, $-0.0$ is returned instead.
404    ///
405    /// Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within
406    /// $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of
407    /// precision, or an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond
408    /// the largest finite [`Float`].
409    ///
410    /// If you know you'll be using `Nearest`, consider using [`Float::csc_prec_ref`] instead. If
411    /// you know that your target precision is the precision of the input, consider using
412    /// [`Float::csc_round_ref`] instead. If both of these things are true, consider using
413    /// `(&Float).csc()` instead.
414    ///
415    /// # Worst-case complexity
416    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
417    ///
418    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
419    ///
420    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is
421    /// `self.significant_bits()`, and $e$ is the exponent of `self` (0 if `self` has no exponent or
422    /// a negative one): the cosine at working precision $n$, summed by binary splitting of the
423    /// Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$
424    /// the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a
425    /// remainder of the $m$-bit input. Unlike most functions, `csc` therefore gets slower as the
426    /// magnitude of its input grows, not just as the precision does.
427    ///
428    /// # Panics
429    /// Panics if `rm` is `Exact`, since the cosecant of a finite nonzero [`Float`] is never exactly
430    /// representable, or if `prec` is zero.
431    ///
432    /// # Examples
433    /// ```
434    /// use malachite_base::rounding_modes::RoundingMode::*;
435    /// use malachite_float::Float;
436    /// use std::cmp::Ordering::*;
437    ///
438    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(5, Floor);
439    /// assert_eq!(c.to_string(), "1.19");
440    /// assert_eq!(o, Less);
441    ///
442    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(5, Ceiling);
443    /// assert_eq!(c.to_string(), "1.25");
444    /// assert_eq!(o, Greater);
445    ///
446    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(5, Nearest);
447    /// assert_eq!(c.to_string(), "1.19");
448    /// assert_eq!(o, Less);
449    ///
450    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(20, Floor);
451    /// assert_eq!(c.to_string(), "1.1883945");
452    /// assert_eq!(o, Less);
453    ///
454    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(20, Ceiling);
455    /// assert_eq!(c.to_string(), "1.1883965");
456    /// assert_eq!(o, Greater);
457    ///
458    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_round_ref(20, Nearest);
459    /// assert_eq!(c.to_string(), "1.1883945");
460    /// assert_eq!(o, Less);
461    /// ```
462    pub fn csc_prec_round_ref(&self, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
463        assert_ne!(prec, 0);
464        match &self.0 {
465            NaN | Infinity { .. } => (Self::NAN, Equal),
466            // csc(+0) = +infinity, csc(-0) = -infinity
467            Zero { .. } => (
468                if self.is_sign_negative() {
469                    Self::NEGATIVE_INFINITY
470                } else {
471                    Self::INFINITY
472                },
473                Equal,
474            ),
475            Finite { .. } => csc_prec_round_normal_ref(self, prec, rm),
476        }
477    }
478
479    /// Computes $\csc x$, the cosecant of a [`Float`], rounding the result to the nearest value of
480    /// the specified precision. The [`Float`] is taken by value. An [`Ordering`] is also returned,
481    /// indicating whether the rounded cosecant is less than, equal to, or greater than the exact
482    /// cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this function
483    /// returns a `NaN` it also returns `Equal`.
484    ///
485    /// If the cosecant is equidistant from two [`Float`]s with the specified precision, the
486    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
487    /// description of the `Nearest` rounding mode.
488    ///
489    /// $$
490    /// f(x,p) = \csc x+\varepsilon.
491    /// $$
492    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
493    /// - If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p}$.
494    ///
495    /// If the output has a precision, it is `prec`.
496    ///
497    /// Special cases:
498    /// - $f(\text{NaN},p)=\text{NaN}$
499    /// - $f(\pm\infty,p)=\text{NaN}$
500    /// - $f(\pm0.0,p)=\pm\infty$
501    ///
502    /// Overflow:
503    /// - If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
504    /// - If $f(x,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
505    /// - If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
506    /// - If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.
507    ///
508    /// Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within
509    /// $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of
510    /// precision, or an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond
511    /// the largest finite [`Float`].
512    ///
513    /// If you want to use a rounding mode other than `Nearest`, consider using
514    /// [`Float::csc_prec_round`] instead. If you know that your target precision is the precision
515    /// of the input, consider using [`Float::csc`] instead.
516    ///
517    /// # Worst-case complexity
518    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
519    ///
520    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
521    ///
522    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is
523    /// `self.significant_bits()`, and $e$ is the exponent of `self` (0 if `self` has no exponent or
524    /// a negative one): the cosine at working precision $n$, summed by binary splitting of the
525    /// Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$
526    /// the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a
527    /// remainder of the $m$-bit input. Unlike most functions, `csc` therefore gets slower as the
528    /// magnitude of its input grows, not just as the precision does.
529    ///
530    /// # Panics
531    /// Panics if `prec` is zero.
532    ///
533    /// # Examples
534    /// ```
535    /// use malachite_float::Float;
536    /// use std::cmp::Ordering::*;
537    ///
538    /// let (c, o) = Float::from_unsigned_prec(1u32, 100).0.csc_prec(5);
539    /// assert_eq!(c.to_string(), "1.19");
540    /// assert_eq!(o, Less);
541    ///
542    /// let (c, o) = Float::from_unsigned_prec(1u32, 100).0.csc_prec(20);
543    /// assert_eq!(c.to_string(), "1.1883945");
544    /// assert_eq!(o, Less);
545    /// ```
546    #[inline]
547    pub fn csc_prec(self, prec: u64) -> (Self, Ordering) {
548        self.csc_prec_round(prec, Nearest)
549    }
550
551    /// Computes $\csc x$, the cosecant of a [`Float`], rounding the result to the nearest value of
552    /// the specified precision. The [`Float`] is taken by reference. An [`Ordering`] is also
553    /// returned, indicating whether the rounded cosecant is less than, equal to, or greater than
554    /// the exact cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this
555    /// function returns a `NaN` it also returns `Equal`.
556    ///
557    /// If the cosecant is equidistant from two [`Float`]s with the specified precision, the
558    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
559    /// description of the `Nearest` rounding mode.
560    ///
561    /// $$
562    /// f(x,p) = \csc x+\varepsilon.
563    /// $$
564    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
565    /// - If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p}$.
566    ///
567    /// If the output has a precision, it is `prec`.
568    ///
569    /// Special cases:
570    /// - $f(\text{NaN},p)=\text{NaN}$
571    /// - $f(\pm\infty,p)=\text{NaN}$
572    /// - $f(\pm0.0,p)=\pm\infty$
573    ///
574    /// Overflow:
575    /// - If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
576    /// - If $f(x,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
577    /// - If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
578    /// - If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.
579    ///
580    /// Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within
581    /// $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of
582    /// precision, or an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond
583    /// the largest finite [`Float`].
584    ///
585    /// If you want to use a rounding mode other than `Nearest`, consider using
586    /// [`Float::csc_prec_round_ref`] instead. If you know that your target precision is the
587    /// precision of the input, consider using `(&Float).csc()` instead.
588    ///
589    /// # Worst-case complexity
590    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
591    ///
592    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
593    ///
594    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is
595    /// `self.significant_bits()`, and $e$ is the exponent of `self` (0 if `self` has no exponent or
596    /// a negative one): the cosine at working precision $n$, summed by binary splitting of the
597    /// Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$
598    /// the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a
599    /// remainder of the $m$-bit input. Unlike most functions, `csc` therefore gets slower as the
600    /// magnitude of its input grows, not just as the precision does.
601    ///
602    /// # Panics
603    /// Panics if `prec` is zero.
604    ///
605    /// # Examples
606    /// ```
607    /// use malachite_float::Float;
608    /// use std::cmp::Ordering::*;
609    ///
610    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_ref(5);
611    /// assert_eq!(c.to_string(), "1.19");
612    /// assert_eq!(o, Less);
613    ///
614    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_prec_ref(20);
615    /// assert_eq!(c.to_string(), "1.1883945");
616    /// assert_eq!(o, Less);
617    /// ```
618    #[inline]
619    pub fn csc_prec_ref(&self, prec: u64) -> (Self, Ordering) {
620        self.csc_prec_round_ref(prec, Nearest)
621    }
622
623    /// Computes $\csc x$, the cosecant of a [`Float`], rounding the result with the specified
624    /// rounding mode. The [`Float`] is taken by value. An [`Ordering`] is also returned, indicating
625    /// whether the rounded cosecant is less than, equal to, or greater than the exact cosecant.
626    /// Although `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN`
627    /// it also returns `Equal`.
628    ///
629    /// The precision of the output is the precision of the input. See [`RoundingMode`] for a
630    /// description of the possible rounding modes.
631    ///
632    /// $$
633    /// f(x,m) = \csc x+\varepsilon.
634    /// $$
635    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
636    /// - If $x$ is finite and $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc
637    ///   x|\rfloor-p+1}$, where $p$ is the precision of the input.
638    /// - If $x$ is finite and $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc
639    ///   x|\rfloor-p}$, where $p$ is the precision of the input.
640    ///
641    /// If the output has a precision, it is the precision of the input.
642    ///
643    /// Special cases:
644    /// - $f(\text{NaN},m)=\text{NaN}$
645    /// - $f(\pm\infty,m)=\text{NaN}$
646    /// - $f(\pm0.0,m)=\pm\infty$
647    ///
648    /// Overflow:
649    /// - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is `Ceiling`, `Up`, or `Nearest`, $\infty$ is
650    ///   returned instead.
651    /// - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is `Floor` or `Down`, $(1-(1/2)^p)2^{2^{30}-1}$ is
652    ///   returned instead.
653    /// - If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is `Floor`, `Up`, or `Nearest`, $-\infty$ is
654    ///   returned instead.
655    /// - If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is `Ceiling` or `Down`, $-(1-(1/2)^p)2^{2^{30}-1}$
656    ///   is returned instead.
657    /// - If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is `Nearest`, $0.0$ is returned instead.
658    /// - If $-2^{-2^{30}-1}\leq f(x,m)<0$, and $m$ is `Nearest`, $-0.0$ is returned instead.
659    ///
660    /// Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within
661    /// $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of
662    /// precision, or an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond
663    /// the largest finite [`Float`].
664    ///
665    /// If you want to specify an output precision, consider using [`Float::csc_prec_round`]
666    /// instead. If you know you'll be using the `Nearest` rounding mode, consider using
667    /// [`Float::csc`] instead.
668    ///
669    /// # Worst-case complexity
670    /// $T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$
671    ///
672    /// $M(n, e) = O((n+e) \log (n+e))$
673    ///
674    /// where $T$ is time, $M$ is additional memory, $n$ is `self.significant_bits()`, and $e$ is
675    /// the exponent of `self` (0 if `self` has no exponent or a negative one): the Taylor series at
676    /// working precision $n$, summed by binary splitting for large $n$, costs the first term, and
677    /// for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n +
678    /// e$ bits. Unlike most functions, `csc` therefore gets slower as the magnitude of its input
679    /// grows, not just as the precision does.
680    ///
681    /// # Panics
682    /// Panics if `rm` is `Exact`, since the cosecant of a finite nonzero [`Float`] is never exactly
683    /// representable.
684    ///
685    /// # Examples
686    /// ```
687    /// use malachite_base::rounding_modes::RoundingMode::*;
688    /// use malachite_float::Float;
689    /// use std::cmp::Ordering::*;
690    ///
691    /// let (c, o) = Float::from_unsigned_prec(1u32, 100).0.csc_round(Floor);
692    /// assert_eq!(c.to_string(), "1.1883951057781212162615994523744");
693    /// assert_eq!(o, Less);
694    ///
695    /// let (c, o) = Float::from_unsigned_prec(1u32, 100).0.csc_round(Ceiling);
696    /// assert_eq!(c.to_string(), "1.1883951057781212162615994523760");
697    /// assert_eq!(o, Greater);
698    ///
699    /// let (c, o) = Float::from_unsigned_prec(1u32, 100).0.csc_round(Nearest);
700    /// assert_eq!(c.to_string(), "1.1883951057781212162615994523744");
701    /// assert_eq!(o, Less);
702    /// ```
703    #[inline]
704    pub fn csc_round(self, rm: RoundingMode) -> (Self, Ordering) {
705        let prec = self.significant_bits();
706        self.csc_prec_round(prec, rm)
707    }
708
709    /// Computes $\csc x$, the cosecant of a [`Float`], rounding the result with the specified
710    /// rounding mode. The [`Float`] is taken by reference. An [`Ordering`] is also returned,
711    /// indicating whether the rounded cosecant is less than, equal to, or greater than the exact
712    /// cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this function
713    /// returns a `NaN` it also returns `Equal`.
714    ///
715    /// The precision of the output is the precision of the input. See [`RoundingMode`] for a
716    /// description of the possible rounding modes.
717    ///
718    /// $$
719    /// f(x,m) = \csc x+\varepsilon.
720    /// $$
721    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
722    /// - If $x$ is finite and $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc
723    ///   x|\rfloor-p+1}$, where $p$ is the precision of the input.
724    /// - If $x$ is finite and $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc
725    ///   x|\rfloor-p}$, where $p$ is the precision of the input.
726    ///
727    /// If the output has a precision, it is the precision of the input.
728    ///
729    /// Special cases:
730    /// - $f(\text{NaN},m)=\text{NaN}$
731    /// - $f(\pm\infty,m)=\text{NaN}$
732    /// - $f(\pm0.0,m)=\pm\infty$
733    ///
734    /// Overflow:
735    /// - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is `Ceiling`, `Up`, or `Nearest`, $\infty$ is
736    ///   returned instead.
737    /// - If $f(x,m)\geq 2^{2^{30}-1}$ and $m$ is `Floor` or `Down`, $(1-(1/2)^p)2^{2^{30}-1}$ is
738    ///   returned instead.
739    /// - If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is `Floor`, `Up`, or `Nearest`, $-\infty$ is
740    ///   returned instead.
741    /// - If $f(x,m)\leq -2^{2^{30}-1}$ and $m$ is `Ceiling` or `Down`, $-(1-(1/2)^p)2^{2^{30}-1}$
742    ///   is returned instead.
743    /// - If $0<f(x,m)\leq2^{-2^{30}-1}$, and $m$ is `Nearest`, $0.0$ is returned instead.
744    /// - If $-2^{-2^{30}-1}\leq f(x,m)<0$, and $m$ is `Nearest`, $-0.0$ is returned instead.
745    ///
746    /// Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within
747    /// $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes more than $2^{30}$ bits of
748    /// precision, or an input of magnitude about $2^{-2^{30}}$, whose reciprocal alone is beyond
749    /// the largest finite [`Float`].
750    ///
751    /// If you want to specify an output precision, consider using [`Float::csc_prec_round_ref`]
752    /// instead. If you know you'll be using the `Nearest` rounding mode, consider using
753    /// `(&Float).csc()` instead.
754    ///
755    /// # Worst-case complexity
756    /// $T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$
757    ///
758    /// $M(n, e) = O((n+e) \log (n+e))$
759    ///
760    /// where $T$ is time, $M$ is additional memory, $n$ is `self.significant_bits()`, and $e$ is
761    /// the exponent of `self` (0 if `self` has no exponent or a negative one): the Taylor series at
762    /// working precision $n$, summed by binary splitting for large $n$, costs the first term, and
763    /// for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n +
764    /// e$ bits. Unlike most functions, `csc` therefore gets slower as the magnitude of its input
765    /// grows, not just as the precision does.
766    ///
767    /// # Panics
768    /// Panics if `rm` is `Exact`, since the cosecant of a finite nonzero [`Float`] is never exactly
769    /// representable.
770    ///
771    /// # Examples
772    /// ```
773    /// use malachite_base::rounding_modes::RoundingMode::*;
774    /// use malachite_float::Float;
775    /// use std::cmp::Ordering::*;
776    ///
777    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_round_ref(Floor);
778    /// assert_eq!(c.to_string(), "1.1883951057781212162615994523744");
779    /// assert_eq!(o, Less);
780    ///
781    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_round_ref(Ceiling);
782    /// assert_eq!(c.to_string(), "1.1883951057781212162615994523760");
783    /// assert_eq!(o, Greater);
784    ///
785    /// let (c, o) = (&Float::from_unsigned_prec(1u32, 100).0).csc_round_ref(Nearest);
786    /// assert_eq!(c.to_string(), "1.1883951057781212162615994523744");
787    /// assert_eq!(o, Less);
788    /// ```
789    #[inline]
790    pub fn csc_round_ref(&self, rm: RoundingMode) -> (Self, Ordering) {
791        self.csc_prec_round_ref(self.significant_bits(), rm)
792    }
793
794    /// Computes $\csc x$, the cosecant of a [`Float`], rounding the result to the specified
795    /// precision and with the specified rounding mode. The [`Float`] is replaced by the result, and
796    /// an [`Ordering`] is returned, indicating whether the rounded cosecant is less than, equal to,
797    /// or greater than the exact cosecant. Although `NaN`s are not comparable to any [`Float`],
798    /// whenever this function sets a `NaN` it also returns `Equal`.
799    ///
800    /// See [`RoundingMode`] for a description of the possible rounding modes.
801    ///
802    /// $$
803    /// x \gets \csc x+\varepsilon.
804    /// $$
805    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
806    /// - If $x$ is finite and $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc
807    ///   x|\rfloor-p+1}$.
808    /// - If $x$ is finite and $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc
809    ///   x|\rfloor-p}$.
810    ///
811    /// If the output has a precision, it is `prec`.
812    ///
813    /// See the [`Float::csc_prec_round`] documentation for information on special cases and
814    /// overflow.
815    ///
816    /// If you know you'll be using `Nearest`, consider using [`Float::csc_prec_assign`] instead. If
817    /// you know that your target precision is the precision of the input, consider using
818    /// [`Float::csc_round_assign`] instead. If both of these things are true, consider using
819    /// [`Float::csc_assign`] instead.
820    ///
821    /// # Worst-case complexity
822    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
823    ///
824    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
825    ///
826    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is
827    /// `self.significant_bits()`, and $e$ is the exponent of `self` (0 if `self` has no exponent or
828    /// a negative one): the cosine at working precision $n$, summed by binary splitting of the
829    /// Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$
830    /// the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a
831    /// remainder of the $m$-bit input. Unlike most functions, `csc` therefore gets slower as the
832    /// magnitude of its input grows, not just as the precision does.
833    ///
834    /// # Panics
835    /// Panics if `rm` is `Exact`, since the cosecant of a finite nonzero [`Float`] is never exactly
836    /// representable, or if `prec` is zero.
837    ///
838    /// # Examples
839    /// ```
840    /// use malachite_base::rounding_modes::RoundingMode::*;
841    /// use malachite_float::Float;
842    /// use std::cmp::Ordering::*;
843    ///
844    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
845    /// assert_eq!(x.csc_prec_round_assign(5, Floor), Less);
846    /// assert_eq!(x.to_string(), "1.19");
847    ///
848    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
849    /// assert_eq!(x.csc_prec_round_assign(5, Ceiling), Greater);
850    /// assert_eq!(x.to_string(), "1.25");
851    ///
852    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
853    /// assert_eq!(x.csc_prec_round_assign(5, Nearest), Less);
854    /// assert_eq!(x.to_string(), "1.19");
855    ///
856    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
857    /// assert_eq!(x.csc_prec_round_assign(20, Floor), Less);
858    /// assert_eq!(x.to_string(), "1.1883945");
859    ///
860    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
861    /// assert_eq!(x.csc_prec_round_assign(20, Ceiling), Greater);
862    /// assert_eq!(x.to_string(), "1.1883965");
863    ///
864    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
865    /// assert_eq!(x.csc_prec_round_assign(20, Nearest), Less);
866    /// assert_eq!(x.to_string(), "1.1883945");
867    /// ```
868    #[inline]
869    pub fn csc_prec_round_assign(&mut self, prec: u64, rm: RoundingMode) -> Ordering {
870        let o;
871        (*self, o) = self.csc_prec_round_ref(prec, rm);
872        o
873    }
874
875    /// Computes $\csc x$, the cosecant of a [`Float`], rounding the result to the nearest value of
876    /// the specified precision. The [`Float`] is replaced by the result, and an [`Ordering`] is
877    /// returned, indicating whether the rounded cosecant is less than, equal to, or greater than
878    /// the exact cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this
879    /// function sets a `NaN` it also returns `Equal`.
880    ///
881    /// If the cosecant is equidistant from two [`Float`]s with the specified precision, the
882    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
883    /// description of the `Nearest` rounding mode.
884    ///
885    /// $$
886    /// x \gets \csc x+\varepsilon.
887    /// $$
888    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
889    /// - If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p}$.
890    ///
891    /// If the output has a precision, it is `prec`.
892    ///
893    /// See the [`Float::csc_prec`] documentation for information on special cases and overflow.
894    ///
895    /// If you want to use a rounding mode other than `Nearest`, consider using
896    /// [`Float::csc_prec_round_assign`] instead. If you know that your target precision is the
897    /// precision of the input, consider using [`Float::csc_assign`] instead.
898    ///
899    /// # Worst-case complexity
900    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
901    ///
902    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
903    ///
904    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is
905    /// `self.significant_bits()`, and $e$ is the exponent of `self` (0 if `self` has no exponent or
906    /// a negative one): the cosine at working precision $n$, summed by binary splitting of the
907    /// Taylor series for large $n$, and its reciprocal cost the first term, and for $|x| \geq 4$
908    /// the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n + e$ bits and a
909    /// remainder of the $m$-bit input. Unlike most functions, `csc` therefore gets slower as the
910    /// magnitude of its input grows, not just as the precision does.
911    ///
912    /// # Panics
913    /// Panics if `prec` is zero.
914    ///
915    /// # Examples
916    /// ```
917    /// use malachite_float::Float;
918    /// use std::cmp::Ordering::*;
919    ///
920    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
921    /// assert_eq!(x.csc_prec_assign(5), Less);
922    /// assert_eq!(x.to_string(), "1.19");
923    ///
924    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
925    /// assert_eq!(x.csc_prec_assign(20), Less);
926    /// assert_eq!(x.to_string(), "1.1883945");
927    /// ```
928    #[inline]
929    pub fn csc_prec_assign(&mut self, prec: u64) -> Ordering {
930        self.csc_prec_round_assign(prec, Nearest)
931    }
932
933    /// Computes $\csc x$, the cosecant of a [`Float`], rounding the result with the specified
934    /// rounding mode. The [`Float`] is replaced by the result, and an [`Ordering`] is returned,
935    /// indicating whether the rounded cosecant is less than, equal to, or greater than the exact
936    /// cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this function sets a
937    /// `NaN` it also returns `Equal`.
938    ///
939    /// The precision of the output is the precision of the input. See [`RoundingMode`] for a
940    /// description of the possible rounding modes.
941    ///
942    /// $$
943    /// x \gets \csc x+\varepsilon.
944    /// $$
945    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
946    /// - If $x$ is finite and $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc
947    ///   x|\rfloor-p+1}$, where $p$ is the precision of the input.
948    /// - If $x$ is finite and $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc
949    ///   x|\rfloor-p}$, where $p$ is the precision of the input.
950    ///
951    /// If the output has a precision, it is the precision of the input.
952    ///
953    /// See the [`Float::csc_round`] documentation for information on special cases and overflow.
954    ///
955    /// If you want to specify an output precision, consider using [`Float::csc_prec_round_assign`]
956    /// instead. If you know you'll be using the `Nearest` rounding mode, consider using
957    /// [`Float::csc_assign`] instead.
958    ///
959    /// # Worst-case complexity
960    /// $T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$
961    ///
962    /// $M(n, e) = O((n+e) \log (n+e))$
963    ///
964    /// where $T$ is time, $M$ is additional memory, $n$ is `self.significant_bits()`, and $e$ is
965    /// the exponent of `self` (0 if `self` has no exponent or a negative one): the Taylor series at
966    /// working precision $n$, summed by binary splitting for large $n$, costs the first term, and
967    /// for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n +
968    /// e$ bits. Unlike most functions, `csc` therefore gets slower as the magnitude of its input
969    /// grows, not just as the precision does.
970    ///
971    /// # Panics
972    /// Panics if `rm` is `Exact`, since the cosecant of a finite nonzero [`Float`] is never exactly
973    /// representable.
974    ///
975    /// # Examples
976    /// ```
977    /// use malachite_base::rounding_modes::RoundingMode::*;
978    /// use malachite_float::Float;
979    /// use std::cmp::Ordering::*;
980    ///
981    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
982    /// assert_eq!(x.csc_round_assign(Floor), Less);
983    /// assert_eq!(x.to_string(), "1.1883951057781212162615994523744");
984    ///
985    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
986    /// assert_eq!(x.csc_round_assign(Ceiling), Greater);
987    /// assert_eq!(x.to_string(), "1.1883951057781212162615994523760");
988    ///
989    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
990    /// assert_eq!(x.csc_round_assign(Nearest), Less);
991    /// assert_eq!(x.to_string(), "1.1883951057781212162615994523744");
992    /// ```
993    #[inline]
994    pub fn csc_round_assign(&mut self, rm: RoundingMode) -> Ordering {
995        let prec = self.significant_bits();
996        self.csc_prec_round_assign(prec, rm)
997    }
998
999    /// Computes $\csc x$, the cosecant of a [`Rational`], rounding the result to the specified
1000    /// precision and with the specified rounding mode and returning the result as a [`Float`]. The
1001    /// [`Rational`] is taken by value. An [`Ordering`] is also returned, indicating whether the
1002    /// rounded cosecant is less than, equal to, or greater than the exact cosecant.
1003    ///
1004    /// See [`RoundingMode`] for a description of the possible rounding modes.
1005    ///
1006    /// $$
1007    /// f(x,p,m) = \csc x+\varepsilon.
1008    /// $$
1009    /// - If $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p+1}$.
1010    /// - If $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc x|\rfloor-p}$.
1011    ///
1012    /// These bounds do not apply when the result overflows; see below.
1013    ///
1014    /// The output has precision `prec`.
1015    ///
1016    /// Special cases:
1017    /// - $f(0,p,m)=\infty$.
1018    ///
1019    /// Overflow:
1020    /// - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is `Ceiling`, `Up`, or `Nearest`, $\infty$ is
1021    ///   returned instead.
1022    /// - If $f(x,p,m)\geq 2^{2^{30}-1}$ and $m$ is `Floor` or `Down`, $(1-(1/2)^p)2^{2^{30}-1}$ is
1023    ///   returned instead.
1024    /// - If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is `Floor`, `Up`, or `Nearest`, $-\infty$ is
1025    ///   returned instead.
1026    /// - If $f(x,p,m)\leq -2^{2^{30}-1}$ and $m$ is `Ceiling` or `Down`, $-(1-(1/2)^p)2^{2^{30}-1}$
1027    ///   is returned instead.
1028    /// - If $0<f(x,p,m)\leq2^{-2^{30}-1}$, and $m$ is `Nearest`, $0.0$ is returned instead.
1029    /// - If $-2^{-2^{30}-1}\leq f(x,p,m)<0$, and $m$ is `Nearest`, $-0.0$ is returned instead.
1030    ///
1031    /// Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within
1032    /// $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes a denominator of more than
1033    /// $2^{30}$ bits, or an input of magnitude about $2^{-2^{30}}$ or below, whose reciprocal alone
1034    /// is beyond the largest finite [`Float`].
1035    ///
1036    /// If you know you'll be using `Nearest`, consider using [`Float::csc_rational_prec`] instead.
1037    ///
1038    /// # Worst-case complexity
1039    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
1040    ///
1041    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
1042    ///
1043    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is `x.significant_bits()`,
1044    /// and $e$ is `x.floor_log_base_2_abs()` (taken as 0 when it is negative or $x = 0$): the input
1045    /// is rounded to a working precision and its [`Float`] cosine taken there, then reciprocated,
1046    /// which for $|x| \geq 2$ reduces the argument modulo $2\pi$ and so needs $\pi$ to about $n +
1047    /// e$ bits.
1048    ///
1049    /// # Panics
1050    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1051    /// with the given precision (which is the case for every nonzero input).
1052    ///
1053    /// # Examples
1054    /// ```
1055    /// use malachite_base::rounding_modes::RoundingMode::*;
1056    /// use malachite_float::Float;
1057    /// use malachite_q::Rational;
1058    /// use std::cmp::Ordering::*;
1059    ///
1060    /// let (c, o) = Float::csc_rational_prec_round(Rational::from_unsigneds(3u8, 5), 5, Floor);
1061    /// assert_eq!(c.to_string(), "1.75");
1062    /// assert_eq!(o, Less);
1063    ///
1064    /// let (c, o) = Float::csc_rational_prec_round(Rational::from_unsigneds(3u8, 5), 5, Ceiling);
1065    /// assert_eq!(c.to_string(), "1.81");
1066    /// assert_eq!(o, Greater);
1067    ///
1068    /// let (c, o) = Float::csc_rational_prec_round(Rational::from_unsigneds(3u8, 5), 20, Floor);
1069    /// assert_eq!(c.to_string(), "1.7710304");
1070    /// assert_eq!(o, Less);
1071    ///
1072    /// let (c, o) = Float::csc_rational_prec_round(Rational::from_unsigneds(3u8, 5), 20, Ceiling);
1073    /// assert_eq!(c.to_string(), "1.7710323");
1074    /// assert_eq!(o, Greater);
1075    /// ```
1076    #[inline]
1077    #[allow(clippy::needless_pass_by_value)]
1078    pub fn csc_rational_prec_round(x: Rational, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
1079        Self::csc_rational_prec_round_ref(&x, prec, rm)
1080    }
1081
1082    /// Computes $\csc x$, the cosecant of a [`Rational`], rounding the result to the specified
1083    /// precision and with the specified rounding mode and returning the result as a [`Float`]. The
1084    /// [`Rational`] is taken by reference. An [`Ordering`] is also returned, indicating whether the
1085    /// rounded cosecant is less than, equal to, or greater than the exact cosecant.
1086    ///
1087    /// See [`RoundingMode`] for a description of the possible rounding modes.
1088    ///
1089    /// $$
1090    /// f(x,p,m) = \csc x+\varepsilon.
1091    /// $$
1092    /// - If $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p+1}$.
1093    /// - If $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc x|\rfloor-p}$.
1094    ///
1095    /// These bounds do not apply when the result overflows.
1096    ///
1097    /// The output has precision `prec`.
1098    ///
1099    /// Special cases:
1100    /// - $f(0,p,m)=\infty$.
1101    ///
1102    /// See the [`Float::csc_rational_prec_round`] documentation for information on overflow.
1103    ///
1104    /// If you know you'll be using `Nearest`, consider using [`Float::csc_rational_prec_ref`]
1105    /// instead.
1106    ///
1107    /// # Worst-case complexity
1108    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
1109    ///
1110    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
1111    ///
1112    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is `x.significant_bits()`,
1113    /// and $e$ is `x.floor_log_base_2_abs()` (taken as 0 when it is negative or $x = 0$): the input
1114    /// is rounded to a working precision and its [`Float`] cosine taken there, then reciprocated,
1115    /// which for $|x| \geq 2$ reduces the argument modulo $2\pi$ and so needs $\pi$ to about $n +
1116    /// e$ bits.
1117    ///
1118    /// # Panics
1119    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1120    /// with the given precision (which is the case for every nonzero input).
1121    ///
1122    /// # Examples
1123    /// ```
1124    /// use malachite_base::rounding_modes::RoundingMode::*;
1125    /// use malachite_float::Float;
1126    /// use malachite_q::Rational;
1127    /// use std::cmp::Ordering::*;
1128    ///
1129    /// let (c, o) =
1130    ///     Float::csc_rational_prec_round_ref(&Rational::from_unsigneds(3u8, 5), 5, Floor);
1131    /// assert_eq!(c.to_string(), "1.75");
1132    /// assert_eq!(o, Less);
1133    ///
1134    /// let (c, o) =
1135    ///     Float::csc_rational_prec_round_ref(&Rational::from_unsigneds(3u8, 5), 5, Ceiling);
1136    /// assert_eq!(c.to_string(), "1.81");
1137    /// assert_eq!(o, Greater);
1138    ///
1139    /// let (c, o) =
1140    ///     Float::csc_rational_prec_round_ref(&Rational::from_unsigneds(3u8, 5), 20, Floor);
1141    /// assert_eq!(c.to_string(), "1.7710304");
1142    /// assert_eq!(o, Less);
1143    ///
1144    /// let (c, o) =
1145    ///     Float::csc_rational_prec_round_ref(&Rational::from_unsigneds(3u8, 5), 20, Ceiling);
1146    /// assert_eq!(c.to_string(), "1.7710323");
1147    /// assert_eq!(o, Greater);
1148    /// ```
1149    pub fn csc_rational_prec_round_ref(
1150        x: &Rational,
1151        prec: u64,
1152        rm: RoundingMode,
1153    ) -> (Self, Ordering) {
1154        assert_ne!(prec, 0);
1155        if *x == 0u32 {
1156            // csc(0) = infinity; a `Rational` zero has no sign, so the result is positive
1157            return (Self::INFINITY, Equal);
1158        }
1159        csc_rational_helper(x, prec, rm)
1160    }
1161
1162    /// Computes $\csc x$, the cosecant of a [`Rational`], rounding the result to the nearest value
1163    /// of the specified precision and returning the result as a [`Float`]. The [`Rational`] is
1164    /// taken by value. An [`Ordering`] is also returned, indicating whether the rounded cosecant is
1165    /// less than, equal to, or greater than the exact cosecant.
1166    ///
1167    /// If the cosecant is equidistant from two [`Float`]s with the specified precision, the
1168    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1169    /// description of the `Nearest` rounding mode.
1170    ///
1171    /// $$
1172    /// f(x,p) = \csc x+\varepsilon,
1173    /// $$
1174    /// where $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc x|\rfloor-p}$ (unless the result overflows;
1175    /// see below).
1176    ///
1177    /// The output has precision `prec`.
1178    ///
1179    /// Special cases:
1180    /// - $f(0,p)=\infty$.
1181    ///
1182    /// Overflow:
1183    /// - If $f(x,p)\geq 2^{2^{30}-1}$, $\infty$ is returned instead.
1184    /// - If $f(x,p)\leq -2^{2^{30}-1}$, $-\infty$ is returned instead.
1185    /// - If $0<f(x,p)\leq2^{-2^{30}-1}$, $0.0$ is returned instead.
1186    /// - If $-2^{-2^{30}-1}\leq f(x,p)<0$, $-0.0$ is returned instead.
1187    ///
1188    /// Underflow is not possible, since $|\csc x| \geq 1$. Overflow requires an input within
1189    /// $2^{-2^{30}}$ of a nonzero multiple of $\pi$, which takes a denominator of more than
1190    /// $2^{30}$ bits, or an input of magnitude about $2^{-2^{30}}$ or below, whose reciprocal alone
1191    /// is beyond the largest finite [`Float`].
1192    ///
1193    /// If you want to use a rounding mode other than `Nearest`, consider using
1194    /// [`Float::csc_rational_prec_round`] instead.
1195    ///
1196    /// # Worst-case complexity
1197    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
1198    ///
1199    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
1200    ///
1201    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is `x.significant_bits()`,
1202    /// and $e$ is `x.floor_log_base_2_abs()` (taken as 0 when it is negative or $x = 0$): the input
1203    /// is rounded to a working precision and its [`Float`] cosine taken there, then reciprocated,
1204    /// which for $|x| \geq 2$ reduces the argument modulo $2\pi$ and so needs $\pi$ to about $n +
1205    /// e$ bits.
1206    ///
1207    /// # Panics
1208    /// Panics if `prec` is zero.
1209    ///
1210    /// # Examples
1211    /// ```
1212    /// use malachite_float::Float;
1213    /// use malachite_q::Rational;
1214    /// use std::cmp::Ordering::*;
1215    ///
1216    /// let (c, o) = Float::csc_rational_prec(Rational::from_unsigneds(3u8, 5), 5);
1217    /// assert_eq!(c.to_string(), "1.75");
1218    /// assert_eq!(o, Less);
1219    ///
1220    /// let (c, o) = Float::csc_rational_prec(Rational::from_unsigneds(3u8, 5), 20);
1221    /// assert_eq!(c.to_string(), "1.7710323");
1222    /// assert_eq!(o, Greater);
1223    /// ```
1224    #[inline]
1225    #[allow(clippy::needless_pass_by_value)]
1226    pub fn csc_rational_prec(x: Rational, prec: u64) -> (Self, Ordering) {
1227        Self::csc_rational_prec_round_ref(&x, prec, Nearest)
1228    }
1229
1230    /// Computes $\csc x$, the cosecant of a [`Rational`], rounding the result to the nearest value
1231    /// of the specified precision and returning the result as a [`Float`]. The [`Rational`] is
1232    /// taken by reference. An [`Ordering`] is also returned, indicating whether the rounded
1233    /// cosecant is less than, equal to, or greater than the exact cosecant.
1234    ///
1235    /// If the cosecant is equidistant from two [`Float`]s with the specified precision, the
1236    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1237    /// description of the `Nearest` rounding mode.
1238    ///
1239    /// $$
1240    /// f(x,p) = \csc x+\varepsilon,
1241    /// $$
1242    /// where $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc x|\rfloor-p}$ (unless the result
1243    /// overflows).
1244    ///
1245    /// The output has precision `prec`.
1246    ///
1247    /// Special cases:
1248    /// - $f(0,p)=\infty$.
1249    ///
1250    /// See the [`Float::csc_rational_prec`] documentation for information on overflow.
1251    ///
1252    /// If you want to use a rounding mode other than `Nearest`, consider using
1253    /// [`Float::csc_rational_prec_round_ref`] instead.
1254    ///
1255    /// # Worst-case complexity
1256    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
1257    ///
1258    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
1259    ///
1260    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is `x.significant_bits()`,
1261    /// and $e$ is `x.floor_log_base_2_abs()` (taken as 0 when it is negative or $x = 0$): the input
1262    /// is rounded to a working precision and its [`Float`] cosine taken there, then reciprocated,
1263    /// which for $|x| \geq 2$ reduces the argument modulo $2\pi$ and so needs $\pi$ to about $n +
1264    /// e$ bits.
1265    ///
1266    /// # Panics
1267    /// Panics if `prec` is zero.
1268    ///
1269    /// # Examples
1270    /// ```
1271    /// use malachite_float::Float;
1272    /// use malachite_q::Rational;
1273    /// use std::cmp::Ordering::*;
1274    ///
1275    /// let (c, o) = Float::csc_rational_prec_ref(&Rational::from_unsigneds(3u8, 5), 5);
1276    /// assert_eq!(c.to_string(), "1.75");
1277    /// assert_eq!(o, Less);
1278    ///
1279    /// let (c, o) = Float::csc_rational_prec_ref(&Rational::from_unsigneds(3u8, 5), 20);
1280    /// assert_eq!(c.to_string(), "1.7710323");
1281    /// assert_eq!(o, Greater);
1282    /// ```
1283    #[inline]
1284    pub fn csc_rational_prec_ref(x: &Rational, prec: u64) -> (Self, Ordering) {
1285        Self::csc_rational_prec_round_ref(x, prec, Nearest)
1286    }
1287
1288    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Float`] measured in $u$ths of a turn,
1289    /// rounding the result to the specified precision and with the specified rounding mode. The
1290    /// [`Float`] is taken by value. An [`Ordering`] is also returned, indicating whether the
1291    /// rounded cosecant is less than, equal to, or greater than the exact cosecant. Although `NaN`s
1292    /// are not comparable to any [`Float`], whenever this function returns a `NaN` it also returns
1293    /// `Equal`.
1294    ///
1295    /// See [`RoundingMode`] for a description of the possible rounding modes.
1296    ///
1297    /// $$
1298    /// f(x,u,p,m) = \csc(2\pi x/u)+\varepsilon.
1299    /// $$
1300    /// - If $x$ is not finite, $u=0$, or $x/u$ is a multiple of $1/4$ or has denominator 12 in
1301    ///   lowest terms, $\varepsilon$ may be ignored or assumed to be 0.
1302    /// - If $x$ is finite, $u\neq 0$, and $m$ is not `Nearest`, then $|\varepsilon| <
1303    ///   2^{\lfloor\log_2 |\csc(2\pi x/u)|\rfloor-p+1}$.
1304    /// - If $x$ is finite, $u\neq 0$, and $m$ is `Nearest`, then $|\varepsilon| \leq
1305    ///   2^{\lfloor\log_2 |\csc(2\pi x/u)|\rfloor-p}$.
1306    ///
1307    /// If the output has a precision, it is `prec`.
1308    ///
1309    /// Special cases:
1310    /// - $f(\text{NaN},u,p,m)=\text{NaN}$
1311    /// - $f(\pm\infty,u,p,m)=\text{NaN}$
1312    /// - $f(x,0,p,m)=\text{NaN}$
1313    /// - $f(\pm0.0,u,p,m)=\pm\infty$
1314    /// - If $x/u$ is a multiple of $1/2$, the cosecant has a pole there, and the result is exactly
1315    ///   $\pm\infty$ with the sign of $x$: the sine is a zero carrying that sign, and the cosecant
1316    ///   is its reciprocal, which keeps the function odd.
1317    /// - If $x/u$ in lowest terms has denominator 4, the result is exactly $\pm1$, and if it has
1318    ///   denominator 12, exactly $\pm2$.
1319    ///
1320    /// When $x/u$ in lowest terms has denominator 3 or 6, the result is $\pm2\sqrt3/3$; when it has
1321    /// denominator 8, $\pm\sqrt2$; and when it has denominator 20, $\pm2\varphi$ or
1322    /// $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio. Each is computed from a single
1323    /// correctly rounded constant rather than from $\pi$ and a sine, which is far faster.
1324    ///
1325    /// Overflow:
1326    /// - If $f(x,u,p,m)\geq 2^{2^{30}-1}$ and $m$ is `Ceiling`, `Up`, or `Nearest`, $\infty$ is
1327    ///   returned instead.
1328    /// - If $f(x,u,p,m)\geq 2^{2^{30}-1}$ and $m$ is `Floor` or `Down`, $(1-(1/2)^p)2^{2^{30}-1}$
1329    ///   is returned instead.
1330    /// - If $f(x,u,p,m)\leq -2^{2^{30}-1}$ and $m$ is `Floor`, `Up`, or `Nearest`, $-\infty$ is
1331    ///   returned instead.
1332    /// - If $f(x,u,p,m)\leq -2^{2^{30}-1}$ and $m$ is `Ceiling` or `Down`,
1333    ///   $-(1-(1/2)^p)2^{2^{30}-1}$ is returned instead.
1334    /// - If $0<f(x,u,p,m)\leq2^{-2^{30}-1}$, and $m$ is `Nearest`, $0.0$ is returned instead.
1335    /// - If $-2^{-2^{30}-1}\leq f(x,u,p,m)<0$, and $m$ is `Nearest`, $-0.0$ is returned instead.
1336    ///
1337    /// Underflow is not possible, since $|\csc(2\pi x/u)| \geq 1$. Overflow requires $x/u$ within
1338    /// $2^{-2^{30}}$ of a multiple of $1/2$ without being one, which takes more than $2^{30}$ bits
1339    /// of precision, or an $x/u$ so small that $2\pi x/u$ is below $2^{-2^{30}}$.
1340    ///
1341    /// If you know you'll be using `Nearest`, consider using [`Float::csc_with_period_prec`]
1342    /// instead. If you know that your target precision is the precision of the input, consider
1343    /// using [`Float::csc_with_period_round`] instead.
1344    ///
1345    /// # Worst-case complexity
1346    /// $T(n, m, e) = O(n (\log n)^3 \log\log n + (n+m+e) (\log (n+m+e))^2 \log\log (n+m+e))$
1347    ///
1348    /// $M(n, m, e) = O((n+m+e) \log (n+m+e))$
1349    ///
1350    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, $m$ is
1351    /// `self.significant_bits()`, and $e$ is the exponent of `self` (0 if `self` has no exponent or
1352    /// a negative one): the argument is reduced modulo $u$ exactly, and the sine of $2\pi x/u$ is
1353    /// then taken at a working precision of about $n + e$ bits, which needs $\pi$ to that many
1354    /// bits, and reciprocated.
1355    ///
1356    /// # Panics
1357    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1358    /// with the given precision (which is the case unless $x/u$ is a multiple of $1/4$ or has
1359    /// denominator 12 in lowest terms, or $x$ is zero or not finite, or $u$ is zero).
1360    ///
1361    /// # Examples
1362    /// ```
1363    /// use malachite_base::num::basic::traits::One;
1364    /// use malachite_base::rounding_modes::RoundingMode::*;
1365    /// use malachite_float::Float;
1366    /// use std::cmp::Ordering::*;
1367    ///
1368    /// let (t, o) = Float::ONE.csc_with_period_prec_round(7, 10, Floor);
1369    /// assert_eq!(t.to_string(), "1.2773");
1370    /// assert_eq!(o, Less);
1371    ///
1372    /// let (t, o) = Float::ONE.csc_with_period_prec_round(7, 10, Ceiling);
1373    /// assert_eq!(t.to_string(), "1.2793");
1374    /// assert_eq!(o, Greater);
1375    ///
1376    /// // a quarter turn is exactly 1
1377    /// let (t, o) = Float::from(90u32).csc_with_period_prec_round(360, 10, Exact);
1378    /// assert_eq!(t.to_string(), "1.0000");
1379    /// assert_eq!(o, Equal);
1380    ///
1381    /// // a half turn is a pole
1382    /// let (t, o) = Float::from(180u32).csc_with_period_prec_round(360, 10, Exact);
1383    /// assert_eq!(t.to_string(), "Infinity");
1384    /// assert_eq!(o, Equal);
1385    ///
1386    /// // a twelfth of a turn is exactly 2
1387    /// let (t, o) = Float::from(30u32).csc_with_period_prec_round(360, 10, Nearest);
1388    /// assert_eq!(t.to_string(), "2.0000");
1389    /// assert_eq!(o, Equal);
1390    /// ```
1391    #[inline]
1392    pub fn csc_with_period_prec_round(
1393        self,
1394        u: u64,
1395        prec: u64,
1396        rm: RoundingMode,
1397    ) -> (Self, Ordering) {
1398        self.csc_with_period_prec_round_ref(u, prec, rm)
1399    }
1400
1401    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Float`] measured in $u$ths of a turn,
1402    /// rounding the result to the specified precision and with the specified rounding mode. The
1403    /// [`Float`] is taken by reference. An [`Ordering`] is also returned, indicating whether the
1404    /// rounded cosecant is less than, equal to, or greater than the exact cosecant. Although `NaN`s
1405    /// are not comparable to any [`Float`], whenever this function returns a `NaN` it also returns
1406    /// `Equal`.
1407    ///
1408    /// See [`Float::csc_with_period_prec_round`] for the error bounds, the special and closed-form
1409    /// cases, overflow, and the complexity; this function behaves the same way.
1410    ///
1411    /// # Panics
1412    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1413    /// with the given precision.
1414    ///
1415    /// # Examples
1416    /// ```
1417    /// use malachite_base::num::basic::traits::One;
1418    /// use malachite_base::rounding_modes::RoundingMode::*;
1419    /// use malachite_float::Float;
1420    /// use std::cmp::Ordering::*;
1421    ///
1422    /// let (t, o) = Float::ONE.csc_with_period_prec_round_ref(7, 10, Floor);
1423    /// assert_eq!(t.to_string(), "1.2773");
1424    /// assert_eq!(o, Less);
1425    /// ```
1426    pub fn csc_with_period_prec_round_ref(
1427        &self,
1428        u: u64,
1429        prec: u64,
1430        rm: RoundingMode,
1431    ) -> (Self, Ordering) {
1432        assert_ne!(prec, 0);
1433        match &self.0 {
1434            // for u=0, return NaN
1435            _ if u == 0 => (Self::NAN, Equal),
1436            NaN | Infinity { .. } => (Self::NAN, Equal),
1437            // x is zero: csc(±0) = ±infinity
1438            Zero { .. } => (
1439                if self.is_sign_negative() {
1440                    Self::NEGATIVE_INFINITY
1441                } else {
1442                    Self::INFINITY
1443                },
1444                Equal,
1445            ),
1446            Finite { .. } => csc_with_period_prec_round_normal_ref(self, u, prec, rm),
1447        }
1448    }
1449
1450    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Float`] measured in $u$ths of a turn,
1451    /// rounding the result to the nearest value of the specified precision. The [`Float`] is taken
1452    /// by value. An [`Ordering`] is also returned, indicating whether the rounded cosecant is less
1453    /// than, equal to, or greater than the exact cosecant. Although `NaN`s are not comparable to
1454    /// any [`Float`], whenever this function returns a `NaN` it also returns `Equal`.
1455    ///
1456    /// If the cosecant is equidistant from two [`Float`]s with the specified precision, the
1457    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1458    /// description of the `Nearest` rounding mode.
1459    ///
1460    /// See [`Float::csc_with_period_prec_round`] for the error bounds, the special and closed-form
1461    /// cases, overflow, and the complexity; this function behaves the same way with `Nearest`.
1462    ///
1463    /// If you want to use a rounding mode other than `Nearest`, consider using
1464    /// [`Float::csc_with_period_prec_round`] instead.
1465    ///
1466    /// # Panics
1467    /// Panics if `prec` is zero.
1468    ///
1469    /// # Examples
1470    /// ```
1471    /// use malachite_base::num::basic::traits::One;
1472    /// use malachite_float::Float;
1473    /// use std::cmp::Ordering::*;
1474    ///
1475    /// let (t, o) = Float::ONE.csc_with_period_prec(7, 10);
1476    /// assert_eq!(t.to_string(), "1.2793");
1477    /// assert_eq!(o, Greater);
1478    ///
1479    /// // an eighth of a turn: sqrt(2)
1480    /// let (t, o) = Float::ONE.csc_with_period_prec(8, 10);
1481    /// assert_eq!(t.to_string(), "1.4141");
1482    /// assert_eq!(o, Less);
1483    /// ```
1484    #[inline]
1485    pub fn csc_with_period_prec(self, u: u64, prec: u64) -> (Self, Ordering) {
1486        self.csc_with_period_prec_round(u, prec, Nearest)
1487    }
1488
1489    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Float`] measured in $u$ths of a turn,
1490    /// rounding the result to the nearest value of the specified precision. The [`Float`] is taken
1491    /// by reference. An [`Ordering`] is also returned, indicating whether the rounded cosecant is
1492    /// less than, equal to, or greater than the exact cosecant. Although `NaN`s are not comparable
1493    /// to any [`Float`], whenever this function returns a `NaN` it also returns `Equal`.
1494    ///
1495    /// See [`Float::csc_with_period_prec`] and [`Float::csc_with_period_prec_round`]; this function
1496    /// behaves the same way.
1497    ///
1498    /// # Panics
1499    /// Panics if `prec` is zero.
1500    ///
1501    /// # Examples
1502    /// ```
1503    /// use malachite_base::num::basic::traits::One;
1504    /// use malachite_float::Float;
1505    /// use std::cmp::Ordering::*;
1506    ///
1507    /// let (t, o) = Float::ONE.csc_with_period_prec_ref(7, 10);
1508    /// assert_eq!(t.to_string(), "1.2793");
1509    /// assert_eq!(o, Greater);
1510    /// ```
1511    #[inline]
1512    pub fn csc_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering) {
1513        self.csc_with_period_prec_round_ref(u, prec, Nearest)
1514    }
1515
1516    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Float`] measured in $u$ths of a turn,
1517    /// rounding the result to the precision of the input and with the specified rounding mode. The
1518    /// [`Float`] is taken by value. An [`Ordering`] is also returned, indicating whether the
1519    /// rounded cosecant is less than, equal to, or greater than the exact cosecant. Although `NaN`s
1520    /// are not comparable to any [`Float`], whenever this function returns a `NaN` it also returns
1521    /// `Equal`.
1522    ///
1523    /// See [`Float::csc_with_period_prec_round`] for the error bounds, the special and closed-form
1524    /// cases, overflow, and the complexity; this function behaves the same way with `prec` equal to
1525    /// the precision of the input.
1526    ///
1527    /// If you want to specify an output precision, consider using
1528    /// [`Float::csc_with_period_prec_round`] instead.
1529    ///
1530    /// # Panics
1531    /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
1532    /// the input.
1533    ///
1534    /// # Examples
1535    /// ```
1536    /// use malachite_base::rounding_modes::RoundingMode::*;
1537    /// use malachite_float::Float;
1538    /// use std::cmp::Ordering::*;
1539    ///
1540    /// let (t, o) = Float::from_unsigned_prec(1u32, 10)
1541    ///     .0
1542    ///     .csc_with_period_round(7, Floor);
1543    /// assert_eq!(t.to_string(), "1.2773");
1544    /// assert_eq!(o, Less);
1545    /// ```
1546    #[inline]
1547    pub fn csc_with_period_round(self, u: u64, rm: RoundingMode) -> (Self, Ordering) {
1548        let prec = self.significant_bits();
1549        self.csc_with_period_prec_round(u, prec, rm)
1550    }
1551
1552    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Float`] measured in $u$ths of a turn,
1553    /// rounding the result to the precision of the input and with the specified rounding mode. The
1554    /// [`Float`] is taken by reference. An [`Ordering`] is also returned, indicating whether the
1555    /// rounded cosecant is less than, equal to, or greater than the exact cosecant. Although `NaN`s
1556    /// are not comparable to any [`Float`], whenever this function returns a `NaN` it also returns
1557    /// `Equal`.
1558    ///
1559    /// See [`Float::csc_with_period_round`] and [`Float::csc_with_period_prec_round`]; this
1560    /// function behaves the same way.
1561    ///
1562    /// # Panics
1563    /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
1564    /// the input.
1565    ///
1566    /// # Examples
1567    /// ```
1568    /// use malachite_base::rounding_modes::RoundingMode::*;
1569    /// use malachite_float::Float;
1570    /// use std::cmp::Ordering::*;
1571    ///
1572    /// let (t, o) = Float::from_unsigned_prec(1u32, 10)
1573    ///     .0
1574    ///     .csc_with_period_round_ref(7, Floor);
1575    /// assert_eq!(t.to_string(), "1.2773");
1576    /// assert_eq!(o, Less);
1577    /// ```
1578    #[inline]
1579    pub fn csc_with_period_round_ref(&self, u: u64, rm: RoundingMode) -> (Self, Ordering) {
1580        self.csc_with_period_prec_round_ref(u, self.significant_bits(), rm)
1581    }
1582
1583    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Float`] measured in $u$ths of a turn (so that
1584    /// `u = 360` is degrees), rounding the result to the precision of the input and to the nearest
1585    /// [`Float`]. The [`Float`] is taken by value.
1586    ///
1587    /// If the cosecant is equidistant from two [`Float`]s with the precision of the input, the
1588    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1589    /// description of the `Nearest` rounding mode.
1590    ///
1591    /// See [`Float::csc_with_period_prec_round`] for the error bounds, the special and closed-form
1592    /// cases, overflow, and the complexity; this function behaves the same way with `prec` equal to
1593    /// the precision of the input and `rm` equal to `Nearest`.
1594    ///
1595    /// If you want to use a rounding mode other than `Nearest`, consider using
1596    /// [`Float::csc_with_period_round`] instead. If you want to specify an output precision,
1597    /// consider using [`Float::csc_with_period_prec`]. If you want both of these things, consider
1598    /// using [`Float::csc_with_period_prec_round`].
1599    ///
1600    /// # Examples
1601    /// ```
1602    /// use malachite_float::Float;
1603    ///
1604    /// let t = Float::from_unsigned_prec(1u32, 10).0.csc_with_period(7);
1605    /// assert_eq!(t.to_string(), "1.2793");
1606    ///
1607    /// // a quarter turn is exactly 1
1608    /// assert_eq!(Float::from(90u32).csc_with_period(360).to_string(), "1.00");
1609    /// ```
1610    #[inline]
1611    pub fn csc_with_period(self, u: u64) -> Self {
1612        let prec = self.significant_bits();
1613        self.csc_with_period_prec(u, prec).0
1614    }
1615
1616    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Float`] measured in $u$ths of a turn (so that
1617    /// `u = 360` is degrees), rounding the result to the precision of the input and to the nearest
1618    /// [`Float`]. The [`Float`] is taken by reference.
1619    ///
1620    /// If the cosecant is equidistant from two [`Float`]s with the precision of the input, the
1621    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1622    /// description of the `Nearest` rounding mode.
1623    ///
1624    /// See [`Float::csc_with_period_prec_round`] for the error bounds, the special and closed-form
1625    /// cases, overflow, and the complexity; this function behaves the same way with `prec` equal to
1626    /// the precision of the input and `rm` equal to `Nearest`.
1627    ///
1628    /// If you want to use a rounding mode other than `Nearest`, consider using
1629    /// [`Float::csc_with_period_round_ref`] instead. If you want to specify an output precision,
1630    /// consider using [`Float::csc_with_period_prec_ref`]. If you want both of these things,
1631    /// consider using [`Float::csc_with_period_prec_round_ref`].
1632    ///
1633    /// # Examples
1634    /// ```
1635    /// use malachite_float::Float;
1636    ///
1637    /// let t = (&Float::from_unsigned_prec(1u32, 10).0).csc_with_period_ref(7);
1638    /// assert_eq!(t.to_string(), "1.2793");
1639    /// ```
1640    #[inline]
1641    pub fn csc_with_period_ref(&self, u: u64) -> Self {
1642        self.csc_with_period_prec_ref(u, self.significant_bits()).0
1643    }
1644
1645    /// Replaces a [`Float`] measured in $u$ths of a turn with its cosecant, rounding the result to
1646    /// the specified precision and with the specified rounding mode. An [`Ordering`] is returned,
1647    /// indicating whether the rounded cosecant is less than, equal to, or greater than the exact
1648    /// cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this function sets a
1649    /// `NaN` it also returns `Equal`.
1650    ///
1651    /// See [`Float::csc_with_period_prec_round`] for the error bounds, the special and closed-form
1652    /// cases, overflow, and the complexity; this function behaves the same way.
1653    ///
1654    /// # Panics
1655    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1656    /// with the given precision.
1657    ///
1658    /// # Examples
1659    /// ```
1660    /// use malachite_base::num::basic::traits::One;
1661    /// use malachite_base::rounding_modes::RoundingMode::*;
1662    /// use malachite_float::Float;
1663    /// use std::cmp::Ordering::*;
1664    ///
1665    /// let mut x = Float::ONE;
1666    /// assert_eq!(x.csc_with_period_prec_round_assign(7, 10, Floor), Less);
1667    /// assert_eq!(x.to_string(), "1.2773");
1668    /// ```
1669    #[inline]
1670    pub fn csc_with_period_prec_round_assign(
1671        &mut self,
1672        u: u64,
1673        prec: u64,
1674        rm: RoundingMode,
1675    ) -> Ordering {
1676        let (t, o) = self.csc_with_period_prec_round_ref(u, prec, rm);
1677        *self = t;
1678        o
1679    }
1680
1681    /// Replaces a [`Float`] measured in $u$ths of a turn with its cosecant, rounding the result to
1682    /// the nearest value of the specified precision. An [`Ordering`] is returned, indicating
1683    /// whether the rounded cosecant is less than, equal to, or greater than the exact cosecant.
1684    /// Although `NaN`s are not comparable to any [`Float`], whenever this function sets a `NaN` it
1685    /// also returns `Equal`.
1686    ///
1687    /// See [`Float::csc_with_period_prec`] and [`Float::csc_with_period_prec_round`]; this function
1688    /// behaves the same way.
1689    ///
1690    /// # Panics
1691    /// Panics if `prec` is zero.
1692    ///
1693    /// # Examples
1694    /// ```
1695    /// use malachite_base::num::basic::traits::One;
1696    /// use malachite_float::Float;
1697    /// use std::cmp::Ordering::*;
1698    ///
1699    /// let mut x = Float::ONE;
1700    /// assert_eq!(x.csc_with_period_prec_assign(7, 10), Greater);
1701    /// assert_eq!(x.to_string(), "1.2793");
1702    /// ```
1703    #[inline]
1704    pub fn csc_with_period_prec_assign(&mut self, u: u64, prec: u64) -> Ordering {
1705        self.csc_with_period_prec_round_assign(u, prec, Nearest)
1706    }
1707
1708    /// Replaces a [`Float`] measured in $u$ths of a turn with its cosecant, rounding the result to
1709    /// the precision of the input and with the specified rounding mode. An [`Ordering`] is
1710    /// returned, indicating whether the rounded cosecant is less than, equal to, or greater than
1711    /// the exact cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this
1712    /// function sets a `NaN` it also returns `Equal`.
1713    ///
1714    /// See [`Float::csc_with_period_round`] and [`Float::csc_with_period_prec_round`]; this
1715    /// function behaves the same way.
1716    ///
1717    /// # Panics
1718    /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
1719    /// the input.
1720    ///
1721    /// # Examples
1722    /// ```
1723    /// use malachite_base::rounding_modes::RoundingMode::*;
1724    /// use malachite_float::Float;
1725    /// use std::cmp::Ordering::*;
1726    ///
1727    /// let mut x = Float::from_unsigned_prec(1u32, 10).0;
1728    /// assert_eq!(x.csc_with_period_round_assign(7, Floor), Less);
1729    /// assert_eq!(x.to_string(), "1.2773");
1730    /// ```
1731    #[inline]
1732    pub fn csc_with_period_round_assign(&mut self, u: u64, rm: RoundingMode) -> Ordering {
1733        let prec = self.significant_bits();
1734        self.csc_with_period_prec_round_assign(u, prec, rm)
1735    }
1736
1737    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Float`] measured in $u$ths of a turn (so that
1738    /// `u = 360` is degrees), rounding the result to the precision of the input and to the nearest
1739    /// [`Float`]. The [`Float`] is replaced by the result.
1740    ///
1741    /// If the cosecant is equidistant from two [`Float`]s with the precision of the input, the
1742    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1743    /// description of the `Nearest` rounding mode.
1744    ///
1745    /// See [`Float::csc_with_period_prec_round`] for the error bounds, the special and closed-form
1746    /// cases, overflow, and the complexity; this function behaves the same way with `prec` equal to
1747    /// the precision of the input and `rm` equal to `Nearest`.
1748    ///
1749    /// If you want to use a rounding mode other than `Nearest`, consider using
1750    /// [`Float::csc_with_period_round_assign`] instead. If you want to specify an output precision,
1751    /// consider using [`Float::csc_with_period_prec_assign`]. If you want both of these things,
1752    /// consider using [`Float::csc_with_period_prec_round_assign`].
1753    ///
1754    /// # Examples
1755    /// ```
1756    /// use malachite_float::Float;
1757    ///
1758    /// let mut x = Float::from_unsigned_prec(1u32, 10).0;
1759    /// x.csc_with_period_assign(7);
1760    /// assert_eq!(x.to_string(), "1.2793");
1761    /// ```
1762    #[inline]
1763    pub fn csc_with_period_assign(&mut self, u: u64) {
1764        let prec = self.significant_bits();
1765        self.csc_with_period_prec_assign(u, prec);
1766    }
1767
1768    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Rational`] measured in $u$ths of a turn,
1769    /// rounding the result to the specified precision and with the specified rounding mode, and
1770    /// returning the result as a [`Float`]. The [`Rational`] is taken by value. An [`Ordering`] is
1771    /// also returned, indicating whether the rounded cosecant is less than, equal to, or greater
1772    /// than the exact cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this
1773    /// function returns a `NaN` it also returns `Equal`.
1774    ///
1775    /// See [`RoundingMode`] for a description of the possible rounding modes.
1776    ///
1777    /// $$
1778    /// f(x,u,p,m) = \csc(2\pi x/u)+\varepsilon.
1779    /// $$
1780    /// - If $u=0$ or $x/u$ is a multiple of $1/4$ or has denominator 12 in lowest terms,
1781    ///   $\varepsilon$ may be ignored or assumed to be 0.
1782    /// - If $u\neq 0$ and $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc(2\pi
1783    ///   x/u)|\rfloor-p+1}$.
1784    /// - If $u\neq 0$ and $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2 |\csc(2\pi
1785    ///   x/u)|\rfloor-p}$.
1786    ///
1787    /// If the output has a precision, it is `prec`.
1788    ///
1789    /// Special cases:
1790    /// - $f(x,0,p,m)=\text{NaN}$
1791    /// - $f(0,u,p,m)=\infty$
1792    /// - If $x/u$ is a multiple of $1/2$, the cosecant has a pole there, and the result is exactly
1793    ///   $\pm\infty$ with the sign of $x$: the sine is a zero carrying that sign, and the cosecant
1794    ///   is its reciprocal, which keeps the function odd.
1795    /// - If $x/u$ in lowest terms has denominator 4, the result is exactly $\pm1$, and if it has
1796    ///   denominator 12, exactly $\pm2$.
1797    ///
1798    /// When $x/u$ in lowest terms has denominator 3 or 6, the result is $\pm2\sqrt3/3$; when it has
1799    /// denominator 8, $\pm\sqrt2$; and when it has denominator 20, $\pm2\varphi$ or
1800    /// $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio. Each is computed from a single
1801    /// correctly rounded constant rather than from $\pi$ and a sine, which is far faster.
1802    ///
1803    /// Underflow is not possible, since $|\csc(2\pi x/u)| \geq 1$. Overflow is as for
1804    /// [`Float::csc_with_period_prec_round`], and requires $x/u$ within $2^{-2^{30}}$ of a multiple
1805    /// of $1/2$ without being one, which takes a denominator of more than $2^{30}$ bits, or an
1806    /// $x/u$ so small that $2\pi x/u$ is below $2^{-2^{30}}$; a [`Rational`] can be that small
1807    /// however large its denominator is not.
1808    ///
1809    /// If you know you'll be using `Nearest`, consider using
1810    /// [`Float::csc_with_period_rational_prec`] instead.
1811    ///
1812    /// # Worst-case complexity
1813    /// $T(n, m) = O(n (\log n)^3 \log\log n + (n+m) (\log (n+m))^2 \log\log (n+m))$
1814    ///
1815    /// $M(n, m) = O((n+m) \log (n+m))$
1816    ///
1817    /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, and $m$ is
1818    /// `x.significant_bits()`: the fraction of a turn is reduced modulo 1 exactly, so only its size
1819    /// and the precision drive the cost, not the magnitude of $x$.
1820    ///
1821    /// # Panics
1822    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1823    /// with the given precision (which is the case unless $x/u$ is a multiple of $1/4$ or has
1824    /// denominator 12 in lowest terms, or $x$ or $u$ is zero).
1825    ///
1826    /// # Examples
1827    /// ```
1828    /// use malachite_base::num::basic::traits::One;
1829    /// use malachite_base::rounding_modes::RoundingMode::*;
1830    /// use malachite_float::Float;
1831    /// use malachite_q::Rational;
1832    /// use std::cmp::Ordering::*;
1833    ///
1834    /// let (t, o) = Float::csc_with_period_rational_prec_round(Rational::ONE, 7, 10, Floor);
1835    /// assert_eq!(t.to_string(), "1.2773");
1836    /// assert_eq!(o, Less);
1837    ///
1838    /// let (t, o) = Float::csc_with_period_rational_prec_round(Rational::ONE, 7, 10, Ceiling);
1839    /// assert_eq!(t.to_string(), "1.2793");
1840    /// assert_eq!(o, Greater);
1841    ///
1842    /// // a quarter turn is exactly 1
1843    /// let (t, o) = Float::csc_with_period_rational_prec_round(
1844    ///     Rational::from_unsigneds(1u8, 4),
1845    ///     1,
1846    ///     10,
1847    ///     Exact,
1848    /// );
1849    /// assert_eq!(t.to_string(), "1.0000");
1850    /// assert_eq!(o, Equal);
1851    ///
1852    /// // a twelfth of a turn is exactly 2
1853    /// let (t, o) = Float::csc_with_period_rational_prec_round(
1854    ///     Rational::from_unsigneds(1u8, 12),
1855    ///     1,
1856    ///     10,
1857    ///     Nearest,
1858    /// );
1859    /// assert_eq!(t.to_string(), "2.0000");
1860    /// assert_eq!(o, Equal);
1861    /// ```
1862    #[inline]
1863    #[allow(clippy::needless_pass_by_value)]
1864    pub fn csc_with_period_rational_prec_round(
1865        x: Rational,
1866        u: u64,
1867        prec: u64,
1868        rm: RoundingMode,
1869    ) -> (Self, Ordering) {
1870        Self::csc_with_period_rational_prec_round_ref(&x, u, prec, rm)
1871    }
1872
1873    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Rational`] measured in $u$ths of a turn,
1874    /// rounding the result to the specified precision and with the specified rounding mode, and
1875    /// returning the result as a [`Float`]. The [`Rational`] is taken by reference. An [`Ordering`]
1876    /// is also returned, indicating whether the rounded cosecant is less than, equal to, or greater
1877    /// than the exact cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this
1878    /// function returns a `NaN` it also returns `Equal`.
1879    ///
1880    /// See [`Float::csc_with_period_rational_prec_round`] for the error bounds, the special and
1881    /// closed-form cases, overflow, and the complexity; this function behaves the same way.
1882    ///
1883    /// # Panics
1884    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1885    /// with the given precision.
1886    ///
1887    /// # Examples
1888    /// ```
1889    /// use malachite_base::num::basic::traits::One;
1890    /// use malachite_base::rounding_modes::RoundingMode::*;
1891    /// use malachite_float::Float;
1892    /// use malachite_q::Rational;
1893    /// use std::cmp::Ordering::*;
1894    ///
1895    /// let (t, o) = Float::csc_with_period_rational_prec_round_ref(&Rational::ONE, 7, 10, Floor);
1896    /// assert_eq!(t.to_string(), "1.2773");
1897    /// assert_eq!(o, Less);
1898    /// ```
1899    pub fn csc_with_period_rational_prec_round_ref(
1900        x: &Rational,
1901        u: u64,
1902        prec: u64,
1903        rm: RoundingMode,
1904    ) -> (Self, Ordering) {
1905        assert_ne!(prec, 0);
1906        // for u = 0, return NaN
1907        if u == 0 {
1908            return (Self::NAN, Equal);
1909        }
1910        // csc(0) = infinity (a `Rational` zero has no sign)
1911        if *x == 0u32 {
1912            return (Self::INFINITY, Equal);
1913        }
1914        // q = x/u, reduced to (-1, 1) with the sign of x: csc(2 pi q) has period 1 in q, and a
1915        // multiple of u is a pole, where the sine is a zero with the sign of x and the cosecant is
1916        // an infinity with that sign
1917        let q = x / Rational::from(u) % Rational::ONE;
1918        if q == 0u32 {
1919            return (
1920                if *x < 0u32 {
1921                    Self::NEGATIVE_INFINITY
1922                } else {
1923                    Self::INFINITY
1924                },
1925                Equal,
1926            );
1927        }
1928        csc_turns_helper(&q, prec, rm)
1929    }
1930
1931    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Rational`] measured in $u$ths of a turn,
1932    /// rounding the result to the nearest value of the specified precision, and returning the
1933    /// result as a [`Float`]. The [`Rational`] is taken by value. An [`Ordering`] is also returned,
1934    /// indicating whether the rounded cosecant is less than, equal to, or greater than the exact
1935    /// cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this function
1936    /// returns a `NaN` it also returns `Equal`.
1937    ///
1938    /// If the cosecant is equidistant from two [`Float`]s with the specified precision, the
1939    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1940    /// description of the `Nearest` rounding mode.
1941    ///
1942    /// See [`Float::csc_with_period_rational_prec_round`] for the error bounds, the special and
1943    /// closed-form cases, overflow, and the complexity; this function behaves the same way with
1944    /// `Nearest`.
1945    ///
1946    /// If you want to use a rounding mode other than `Nearest`, consider using
1947    /// [`Float::csc_with_period_rational_prec_round`] instead.
1948    ///
1949    /// # Panics
1950    /// Panics if `prec` is zero.
1951    ///
1952    /// # Examples
1953    /// ```
1954    /// use malachite_base::num::basic::traits::One;
1955    /// use malachite_float::Float;
1956    /// use malachite_q::Rational;
1957    /// use std::cmp::Ordering::*;
1958    ///
1959    /// let (t, o) = Float::csc_with_period_rational_prec(Rational::ONE, 7, 10);
1960    /// assert_eq!(t.to_string(), "1.2793");
1961    /// assert_eq!(o, Greater);
1962    ///
1963    /// // an eighth of a turn: sqrt(2)
1964    /// let (t, o) = Float::csc_with_period_rational_prec(Rational::ONE, 8, 10);
1965    /// assert_eq!(t.to_string(), "1.4141");
1966    /// assert_eq!(o, Less);
1967    /// ```
1968    #[inline]
1969    #[allow(clippy::needless_pass_by_value)]
1970    pub fn csc_with_period_rational_prec(x: Rational, u: u64, prec: u64) -> (Self, Ordering) {
1971        Self::csc_with_period_rational_prec_round_ref(&x, u, prec, Nearest)
1972    }
1973
1974    /// Computes $\csc(2\pi x/u)$, the cosecant of a [`Rational`] measured in $u$ths of a turn,
1975    /// rounding the result to the nearest value of the specified precision, and returning the
1976    /// result as a [`Float`]. The [`Rational`] is taken by reference. An [`Ordering`] is also
1977    /// returned, indicating whether the rounded cosecant is less than, equal to, or greater than
1978    /// the exact cosecant. Although `NaN`s are not comparable to any [`Float`], whenever this
1979    /// function returns a `NaN` it also returns `Equal`.
1980    ///
1981    /// See [`Float::csc_with_period_rational_prec`] and
1982    /// [`Float::csc_with_period_rational_prec_round`]; this function behaves the same way.
1983    ///
1984    /// # Panics
1985    /// Panics if `prec` is zero.
1986    ///
1987    /// # Examples
1988    /// ```
1989    /// use malachite_base::num::basic::traits::One;
1990    /// use malachite_float::Float;
1991    /// use malachite_q::Rational;
1992    /// use std::cmp::Ordering::*;
1993    ///
1994    /// let (t, o) = Float::csc_with_period_rational_prec_ref(&Rational::ONE, 7, 10);
1995    /// assert_eq!(t.to_string(), "1.2793");
1996    /// assert_eq!(o, Greater);
1997    /// ```
1998    #[inline]
1999    pub fn csc_with_period_rational_prec_ref(x: &Rational, u: u64, prec: u64) -> (Self, Ordering) {
2000        Self::csc_with_period_rational_prec_round_ref(x, u, prec, Nearest)
2001    }
2002
2003    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2004    /// result to the specified precision and with the specified rounding mode. The [`Float`] is
2005    /// taken by value. An [`Ordering`] is also returned, indicating whether the rounded cosecant is
2006    /// less than, equal to, or greater than the exact cosecant. Although `NaN`s are not comparable
2007    /// to any [`Float`], whenever this function returns a `NaN` it also returns `Equal`.
2008    ///
2009    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period_prec_round`] for
2010    /// the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$
2011    /// with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd
2012    /// multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give
2013    /// $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where
2014    /// $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.
2015    ///
2016    /// # Panics
2017    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
2018    /// with the given precision.
2019    ///
2020    /// # Examples
2021    /// ```
2022    /// use malachite_base::num::basic::traits::One;
2023    /// use malachite_base::rounding_modes::RoundingMode::*;
2024    /// use malachite_float::Float;
2025    /// use std::cmp::Ordering::*;
2026    ///
2027    /// let (t, o) = Float::from(0.1f64).csc_pi_prec_round(10, Floor);
2028    /// assert_eq!(t.to_string(), "3.2344");
2029    /// assert_eq!(o, Less);
2030    ///
2031    /// let (t, o) = Float::from(0.1f64).csc_pi_prec_round(10, Ceiling);
2032    /// assert_eq!(t.to_string(), "3.2383");
2033    /// assert_eq!(o, Greater);
2034    ///
2035    /// // an integer is a pole
2036    /// let (t, o) = Float::ONE.csc_pi_prec_round(10, Exact);
2037    /// assert_eq!(t.to_string(), "Infinity");
2038    /// assert_eq!(o, Equal);
2039    /// ```
2040    #[inline]
2041    pub fn csc_pi_prec_round(self, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
2042        self.csc_with_period_prec_round(2, prec, rm)
2043    }
2044
2045    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2046    /// result to the specified precision and with the specified rounding mode. The [`Float`] is
2047    /// taken by reference. An [`Ordering`] is also returned, indicating whether the rounded
2048    /// cosecant is less than, equal to, or greater than the exact cosecant. Although `NaN`s are not
2049    /// comparable to any [`Float`], whenever this function returns a `NaN` it also returns `Equal`.
2050    ///
2051    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period_prec_round_ref`]
2052    /// for the error bounds, the special and closed-form cases (integers are poles and give
2053    /// $\pm\infty$ with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give
2054    /// $\pm2$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers
2055    /// give $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$,
2056    /// where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.
2057    ///
2058    /// # Panics
2059    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
2060    /// with the given precision.
2061    ///
2062    /// # Examples
2063    /// ```
2064    /// use malachite_base::num::basic::traits::One;
2065    /// use malachite_base::rounding_modes::RoundingMode::*;
2066    /// use malachite_float::Float;
2067    /// use std::cmp::Ordering::*;
2068    ///
2069    /// let (t, o) = (Float::from(0.1f64)).csc_pi_prec_round_ref(10, Floor);
2070    /// assert_eq!(t.to_string(), "3.2344");
2071    /// assert_eq!(o, Less);
2072    ///
2073    /// let (t, o) = (Float::from(0.1f64)).csc_pi_prec_round_ref(10, Ceiling);
2074    /// assert_eq!(t.to_string(), "3.2383");
2075    /// assert_eq!(o, Greater);
2076    ///
2077    /// // an integer is a pole
2078    /// let (t, o) = (&Float::ONE).csc_pi_prec_round_ref(10, Exact);
2079    /// assert_eq!(t.to_string(), "Infinity");
2080    /// assert_eq!(o, Equal);
2081    /// ```
2082    #[inline]
2083    pub fn csc_pi_prec_round_ref(&self, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
2084        self.csc_with_period_prec_round_ref(2, prec, rm)
2085    }
2086
2087    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2088    /// result to the nearest value of the specified precision. The [`Float`] is taken by value. An
2089    /// [`Ordering`] is also returned, indicating whether the rounded cosecant is less than, equal
2090    /// to, or greater than the exact cosecant. Although `NaN`s are not comparable to any [`Float`],
2091    /// whenever this function returns a `NaN` it also returns `Equal`.
2092    ///
2093    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period_prec`] for the
2094    /// error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$
2095    /// with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd
2096    /// multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give
2097    /// $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where
2098    /// $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.
2099    ///
2100    /// # Panics
2101    /// Panics if `prec` is zero.
2102    ///
2103    /// # Examples
2104    /// ```
2105    /// use malachite_float::Float;
2106    /// use std::cmp::Ordering::*;
2107    ///
2108    /// let (t, o) = Float::from(0.1f64).csc_pi_prec(10);
2109    /// assert_eq!(t.to_string(), "3.2344");
2110    /// assert_eq!(o, Less);
2111    ///
2112    /// let (t, o) = Float::from(0.1f64).csc_pi_prec(53);
2113    /// assert_eq!(t.to_string(), "3.2360679774997894");
2114    /// assert_eq!(o, Less);
2115    /// ```
2116    #[inline]
2117    pub fn csc_pi_prec(self, prec: u64) -> (Self, Ordering) {
2118        self.csc_with_period_prec(2, prec)
2119    }
2120
2121    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2122    /// result to the nearest value of the specified precision. The [`Float`] is taken by reference.
2123    /// An [`Ordering`] is also returned, indicating whether the rounded cosecant is less than,
2124    /// equal to, or greater than the exact cosecant. Although `NaN`s are not comparable to any
2125    /// [`Float`], whenever this function returns a `NaN` it also returns `Equal`.
2126    ///
2127    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period_prec_ref`] for
2128    /// the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$
2129    /// with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd
2130    /// multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give
2131    /// $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where
2132    /// $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.
2133    ///
2134    /// # Panics
2135    /// Panics if `prec` is zero.
2136    ///
2137    /// # Examples
2138    /// ```
2139    /// use malachite_float::Float;
2140    /// use std::cmp::Ordering::*;
2141    ///
2142    /// let (t, o) = (Float::from(0.1f64)).csc_pi_prec_ref(10);
2143    /// assert_eq!(t.to_string(), "3.2344");
2144    /// assert_eq!(o, Less);
2145    ///
2146    /// let (t, o) = (Float::from(0.1f64)).csc_pi_prec_ref(53);
2147    /// assert_eq!(t.to_string(), "3.2360679774997894");
2148    /// assert_eq!(o, Less);
2149    /// ```
2150    #[inline]
2151    pub fn csc_pi_prec_ref(&self, prec: u64) -> (Self, Ordering) {
2152        self.csc_with_period_prec_ref(2, prec)
2153    }
2154
2155    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2156    /// result with the specified rounding mode. The precision of the output is the precision of the
2157    /// input. The [`Float`] is taken by value. An [`Ordering`] is also returned, indicating whether
2158    /// the rounded cosecant is less than, equal to, or greater than the exact cosecant. Although
2159    /// `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN` it also
2160    /// returns `Equal`.
2161    ///
2162    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period_round`] for the
2163    /// error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$
2164    /// with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd
2165    /// multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give
2166    /// $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where
2167    /// $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.
2168    ///
2169    /// # Panics
2170    /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the input
2171    /// precision.
2172    ///
2173    /// # Examples
2174    /// ```
2175    /// use malachite_base::rounding_modes::RoundingMode::*;
2176    /// use malachite_float::Float;
2177    /// use std::cmp::Ordering::*;
2178    ///
2179    /// let (t, o) = Float::from(0.1f64).csc_pi_round(Floor);
2180    /// assert_eq!(t.to_string(), "3.2360679774997889");
2181    /// assert_eq!(o, Less);
2182    ///
2183    /// let (t, o) = Float::from(0.1f64).csc_pi_round(Nearest);
2184    /// assert_eq!(t.to_string(), "3.2360679774997898");
2185    /// assert_eq!(o, Greater);
2186    /// ```
2187    #[inline]
2188    pub fn csc_pi_round(self, rm: RoundingMode) -> (Self, Ordering) {
2189        self.csc_with_period_round(2, rm)
2190    }
2191
2192    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2193    /// result with the specified rounding mode. The precision of the output is the precision of the
2194    /// input. The [`Float`] is taken by reference. An [`Ordering`] is also returned, indicating
2195    /// whether the rounded cosecant is less than, equal to, or greater than the exact cosecant.
2196    /// Although `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN`
2197    /// it also returns `Equal`.
2198    ///
2199    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period_round_ref`] for
2200    /// the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$
2201    /// with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd
2202    /// multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give
2203    /// $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where
2204    /// $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.
2205    ///
2206    /// # Panics
2207    /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the input
2208    /// precision.
2209    ///
2210    /// # Examples
2211    /// ```
2212    /// use malachite_base::rounding_modes::RoundingMode::*;
2213    /// use malachite_float::Float;
2214    /// use std::cmp::Ordering::*;
2215    ///
2216    /// let (t, o) = (Float::from(0.1f64)).csc_pi_round_ref(Floor);
2217    /// assert_eq!(t.to_string(), "3.2360679774997889");
2218    /// assert_eq!(o, Less);
2219    ///
2220    /// let (t, o) = (Float::from(0.1f64)).csc_pi_round_ref(Nearest);
2221    /// assert_eq!(t.to_string(), "3.2360679774997898");
2222    /// assert_eq!(o, Greater);
2223    /// ```
2224    #[inline]
2225    pub fn csc_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering) {
2226        self.csc_with_period_round_ref(2, rm)
2227    }
2228
2229    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2230    /// result to the precision of the input and to the nearest [`Float`]. The [`Float`] is taken by
2231    /// value.
2232    ///
2233    /// If the cosecant is equidistant from two [`Float`]s with the precision of the input, the
2234    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
2235    /// description of the `Nearest` rounding mode.
2236    ///
2237    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period`] for the error
2238    /// bounds, the special and closed-form cases (integers are poles and give $\pm\infty$ with the
2239    /// sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd multiples of
2240    /// $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give $\pm2\sqrt3/3$; and
2241    /// odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the
2242    /// golden ratio), overflow, and the complexity, with $u = 2$.
2243    ///
2244    /// If you want to use a rounding mode other than `Nearest`, consider using
2245    /// [`Float::csc_pi_round`] instead. If you want to specify an output precision, consider using
2246    /// [`Float::csc_pi_prec`]. If you want both of these things, consider using
2247    /// [`Float::csc_pi_prec_round`].
2248    ///
2249    /// # Examples
2250    /// ```
2251    /// use malachite_float::Float;
2252    ///
2253    /// let t = Float::from(0.1f64).csc_pi();
2254    /// assert_eq!(t.to_string(), "3.2360679774997898");
2255    ///
2256    /// // a half-integer is exactly 1
2257    /// assert_eq!(Float::from(0.5f64).csc_pi().to_string(), "1.0");
2258    /// ```
2259    #[inline]
2260    pub fn csc_pi(self) -> Self {
2261        let prec = self.significant_bits();
2262        self.csc_pi_prec(prec).0
2263    }
2264
2265    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2266    /// result to the precision of the input and to the nearest [`Float`]. The [`Float`] is taken by
2267    /// reference.
2268    ///
2269    /// If the cosecant is equidistant from two [`Float`]s with the precision of the input, the
2270    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
2271    /// description of the `Nearest` rounding mode.
2272    ///
2273    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period`] for the error
2274    /// bounds, the special and closed-form cases (integers are poles and give $\pm\infty$ with the
2275    /// sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd multiples of
2276    /// $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give $\pm2\sqrt3/3$; and
2277    /// odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the
2278    /// golden ratio), overflow, and the complexity, with $u = 2$.
2279    ///
2280    /// If you want to use a rounding mode other than `Nearest`, consider using
2281    /// [`Float::csc_pi_round_ref`] instead. If you want to specify an output precision, consider
2282    /// using [`Float::csc_pi_prec_ref`]. If you want both of these things, consider using
2283    /// [`Float::csc_pi_prec_round_ref`].
2284    ///
2285    /// # Examples
2286    /// ```
2287    /// use malachite_float::Float;
2288    ///
2289    /// let t = (&Float::from(0.1f64)).csc_pi_ref();
2290    /// assert_eq!(t.to_string(), "3.2360679774997898");
2291    /// ```
2292    #[inline]
2293    pub fn csc_pi_ref(&self) -> Self {
2294        self.csc_pi_prec_ref(self.significant_bits()).0
2295    }
2296
2297    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2298    /// result to the specified precision and with the specified rounding mode. The [`Float`] is
2299    /// replaced by the result, and an [`Ordering`] is returned, indicating whether the rounded
2300    /// cosecant is less than, equal to, or greater than the exact cosecant. Although `NaN`s are not
2301    /// comparable to any [`Float`], whenever this function sets a `NaN` it also returns `Equal`.
2302    ///
2303    /// This is `csc_with_period` with a period of 2: see
2304    /// [`Float::csc_with_period_prec_round_assign`] for the error bounds, the special and
2305    /// closed-form cases (integers are poles and give $\pm\infty$ with the sign of $x$;
2306    /// half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd multiples of $1/4$ give
2307    /// $\pm\sqrt2$; multiples of $1/3$ that are not integers give $\pm2\sqrt3/3$; and odd multiples
2308    /// of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the golden ratio),
2309    /// overflow, and the complexity, with $u = 2$.
2310    ///
2311    /// # Panics
2312    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
2313    /// with the given precision.
2314    ///
2315    /// # Examples
2316    /// ```
2317    /// use malachite_base::rounding_modes::RoundingMode::*;
2318    /// use malachite_float::Float;
2319    /// use std::cmp::Ordering::*;
2320    ///
2321    /// let mut x = Float::from(0.1f64);
2322    /// assert_eq!(x.csc_pi_prec_round_assign(10, Floor), Less);
2323    /// assert_eq!(x.to_string(), "3.2344");
2324    ///
2325    /// let mut x = Float::from(0.1f64);
2326    /// assert_eq!(x.csc_pi_prec_round_assign(10, Ceiling), Greater);
2327    /// assert_eq!(x.to_string(), "3.2383");
2328    /// ```
2329    #[inline]
2330    pub fn csc_pi_prec_round_assign(&mut self, prec: u64, rm: RoundingMode) -> Ordering {
2331        self.csc_with_period_prec_round_assign(2, prec, rm)
2332    }
2333
2334    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2335    /// result to the nearest value of the specified precision. The [`Float`] is replaced by the
2336    /// result, and an [`Ordering`] is returned, indicating whether the rounded cosecant is less
2337    /// than, equal to, or greater than the exact cosecant. Although `NaN`s are not comparable to
2338    /// any [`Float`], whenever this function sets a `NaN` it also returns `Equal`.
2339    ///
2340    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period_prec_assign`] for
2341    /// the error bounds, the special and closed-form cases (integers are poles and give $\pm\infty$
2342    /// with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd
2343    /// multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give
2344    /// $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where
2345    /// $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.
2346    ///
2347    /// # Panics
2348    /// Panics if `prec` is zero.
2349    ///
2350    /// # Examples
2351    /// ```
2352    /// use malachite_float::Float;
2353    /// use std::cmp::Ordering::*;
2354    ///
2355    /// let mut x = Float::from(0.1f64);
2356    /// assert_eq!(x.csc_pi_prec_assign(10), Less);
2357    /// assert_eq!(x.to_string(), "3.2344");
2358    /// ```
2359    #[inline]
2360    pub fn csc_pi_prec_assign(&mut self, prec: u64) -> Ordering {
2361        self.csc_with_period_prec_assign(2, prec)
2362    }
2363
2364    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2365    /// result with the specified rounding mode. The precision of the output is the precision of the
2366    /// input. The [`Float`] is replaced by the result, and an [`Ordering`] is returned, indicating
2367    /// whether the rounded cosecant is less than, equal to, or greater than the exact cosecant.
2368    /// Although `NaN`s are not comparable to any [`Float`], whenever this function sets a `NaN` it
2369    /// also returns `Equal`.
2370    ///
2371    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period_round_assign`]
2372    /// for the error bounds, the special and closed-form cases (integers are poles and give
2373    /// $\pm\infty$ with the sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give
2374    /// $\pm2$; odd multiples of $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers
2375    /// give $\pm2\sqrt3/3$; and odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$,
2376    /// where $\varphi$ is the golden ratio), overflow, and the complexity, with $u = 2$.
2377    ///
2378    /// # Panics
2379    /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the input
2380    /// precision.
2381    ///
2382    /// # Examples
2383    /// ```
2384    /// use malachite_base::rounding_modes::RoundingMode::*;
2385    /// use malachite_float::Float;
2386    /// use std::cmp::Ordering::*;
2387    ///
2388    /// let mut x = Float::from(0.1f64);
2389    /// assert_eq!(x.csc_pi_round_assign(Floor), Less);
2390    /// assert_eq!(x.to_string(), "3.2360679774997889");
2391    /// ```
2392    #[inline]
2393    pub fn csc_pi_round_assign(&mut self, rm: RoundingMode) -> Ordering {
2394        self.csc_with_period_round_assign(2, rm)
2395    }
2396
2397    /// Computes $\csc(\pi x)$, the cosecant of a [`Float`] measured in half-turns, rounding the
2398    /// result to the precision of the input and to the nearest [`Float`]. The [`Float`] is replaced
2399    /// by the result.
2400    ///
2401    /// If the cosecant is equidistant from two [`Float`]s with the precision of the input, the
2402    /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
2403    /// description of the `Nearest` rounding mode.
2404    ///
2405    /// This is `csc_with_period` with a period of 2: see [`Float::csc_with_period`] for the error
2406    /// bounds, the special and closed-form cases (integers are poles and give $\pm\infty$ with the
2407    /// sign of $x$; half-integers give $\pm1$; odd multiples of $1/6$ give $\pm2$; odd multiples of
2408    /// $1/4$ give $\pm\sqrt2$; multiples of $1/3$ that are not integers give $\pm2\sqrt3/3$; and
2409    /// odd multiples of $1/10$ give $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the
2410    /// golden ratio), overflow, and the complexity, with $u = 2$.
2411    ///
2412    /// If you want to use a rounding mode other than `Nearest`, consider using
2413    /// [`Float::csc_pi_round_assign`] instead. If you want to specify an output precision, consider
2414    /// using [`Float::csc_pi_prec_assign`]. If you want both of these things, consider using
2415    /// [`Float::csc_pi_prec_round_assign`].
2416    ///
2417    /// # Examples
2418    /// ```
2419    /// use malachite_float::Float;
2420    ///
2421    /// let mut x = Float::from(0.1f64);
2422    /// x.csc_pi_assign();
2423    /// assert_eq!(x.to_string(), "3.2360679774997898");
2424    /// ```
2425    #[inline]
2426    pub fn csc_pi_assign(&mut self) {
2427        let prec = self.significant_bits();
2428        self.csc_pi_prec_assign(prec);
2429    }
2430
2431    /// Computes $\csc(\pi x)$, the cosecant of a [`Rational`] measured in half-turns, rounding the
2432    /// result to the specified precision and with the specified rounding mode and returning the
2433    /// result as a [`Float`]. The [`Rational`] is taken by value. An [`Ordering`] is also returned,
2434    /// indicating whether the rounded cosecant is less than, equal to, or greater than the exact
2435    /// cosecant.
2436    ///
2437    /// This is `csc_with_period_rational` with a period of 2: see
2438    /// [`Float::csc_with_period_rational_prec_round`] for the error bounds, the special and
2439    /// closed-form cases, overflow, and the complexity, with $u = 2$.
2440    ///
2441    /// # Panics
2442    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
2443    /// with the given precision.
2444    ///
2445    /// # Examples
2446    /// ```
2447    /// use malachite_base::rounding_modes::RoundingMode::*;
2448    /// use malachite_float::Float;
2449    /// use malachite_q::Rational;
2450    /// use std::cmp::Ordering::*;
2451    ///
2452    /// let (t, o) = Float::csc_pi_rational_prec_round(Rational::from_unsigneds(1u8, 7), 10, Floor);
2453    /// assert_eq!(t.to_string(), "2.3047");
2454    /// assert_eq!(o, Less);
2455    ///
2456    /// // a sixth of a half-turn is exactly 2
2457    /// let (t, o) = Float::csc_pi_rational_prec_round(Rational::from_unsigneds(1u8, 6), 10, Exact);
2458    /// assert_eq!(t.to_string(), "2.0000");
2459    /// assert_eq!(o, Equal);
2460    /// ```
2461    #[inline]
2462    #[allow(clippy::needless_pass_by_value)]
2463    pub fn csc_pi_rational_prec_round(
2464        x: Rational,
2465        prec: u64,
2466        rm: RoundingMode,
2467    ) -> (Self, Ordering) {
2468        Self::csc_with_period_rational_prec_round_ref(&x, 2, prec, rm)
2469    }
2470
2471    /// Computes $\csc(\pi x)$, the cosecant of a [`Rational`] measured in half-turns, rounding the
2472    /// result to the specified precision and with the specified rounding mode and returning the
2473    /// result as a [`Float`]. The [`Rational`] is taken by reference. An [`Ordering`] is also
2474    /// returned, indicating whether the rounded cosecant is less than, equal to, or greater than
2475    /// the exact cosecant.
2476    ///
2477    /// This is `csc_with_period_rational` with a period of 2: see
2478    /// [`Float::csc_with_period_rational_prec_round_ref`] for the error bounds, the special and
2479    /// closed-form cases, overflow, and the complexity, with $u = 2$.
2480    ///
2481    /// # Panics
2482    /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
2483    /// with the given precision.
2484    ///
2485    /// # Examples
2486    /// ```
2487    /// use malachite_base::rounding_modes::RoundingMode::*;
2488    /// use malachite_float::Float;
2489    /// use malachite_q::Rational;
2490    /// use std::cmp::Ordering::*;
2491    ///
2492    /// let (t, o) =
2493    ///     Float::csc_pi_rational_prec_round_ref(&Rational::from_unsigneds(1u8, 7), 10, Ceiling);
2494    /// assert_eq!(t.to_string(), "2.3086");
2495    /// assert_eq!(o, Greater);
2496    /// ```
2497    #[inline]
2498    pub fn csc_pi_rational_prec_round_ref(
2499        x: &Rational,
2500        prec: u64,
2501        rm: RoundingMode,
2502    ) -> (Self, Ordering) {
2503        Self::csc_with_period_rational_prec_round_ref(x, 2, prec, rm)
2504    }
2505
2506    /// Computes $\csc(\pi x)$, the cosecant of a [`Rational`] measured in half-turns, rounding the
2507    /// result to the nearest value of the specified precision and returning the result as a
2508    /// [`Float`]. The [`Rational`] is taken by value. An [`Ordering`] is also returned, indicating
2509    /// whether the rounded cosecant is less than, equal to, or greater than the exact cosecant.
2510    ///
2511    /// This is `csc_with_period_rational` with a period of 2: see
2512    /// [`Float::csc_with_period_rational_prec`] for the error bounds, the special and closed-form
2513    /// cases, overflow, and the complexity, with $u = 2$.
2514    ///
2515    /// # Panics
2516    /// Panics if `prec` is zero.
2517    ///
2518    /// # Examples
2519    /// ```
2520    /// use malachite_float::Float;
2521    /// use malachite_q::Rational;
2522    /// use std::cmp::Ordering::*;
2523    ///
2524    /// let (t, o) = Float::csc_pi_rational_prec(Rational::from_unsigneds(1u8, 7), 53);
2525    /// assert_eq!(t.to_string(), "2.3047648709624866");
2526    /// assert_eq!(o, Greater);
2527    /// ```
2528    #[inline]
2529    #[allow(clippy::needless_pass_by_value)]
2530    pub fn csc_pi_rational_prec(x: Rational, prec: u64) -> (Self, Ordering) {
2531        Self::csc_with_period_rational_prec_ref(&x, 2, prec)
2532    }
2533
2534    /// Computes $\csc(\pi x)$, the cosecant of a [`Rational`] measured in half-turns, rounding the
2535    /// result to the nearest value of the specified precision and returning the result as a
2536    /// [`Float`]. The [`Rational`] is taken by reference. An [`Ordering`] is also returned,
2537    /// indicating whether the rounded cosecant is less than, equal to, or greater than the exact
2538    /// cosecant.
2539    ///
2540    /// This is `csc_with_period_rational` with a period of 2: see
2541    /// [`Float::csc_with_period_rational_prec_ref`] for the error bounds, the special and
2542    /// closed-form cases, overflow, and the complexity, with $u = 2$.
2543    ///
2544    /// # Panics
2545    /// Panics if `prec` is zero.
2546    ///
2547    /// # Examples
2548    /// ```
2549    /// use malachite_float::Float;
2550    /// use malachite_q::Rational;
2551    /// use std::cmp::Ordering::*;
2552    ///
2553    /// let (t, o) = Float::csc_pi_rational_prec_ref(&Rational::from_unsigneds(1u8, 7), 53);
2554    /// assert_eq!(t.to_string(), "2.3047648709624866");
2555    /// assert_eq!(o, Greater);
2556    /// ```
2557    #[inline]
2558    pub fn csc_pi_rational_prec_ref(x: &Rational, prec: u64) -> (Self, Ordering) {
2559        Self::csc_with_period_rational_prec_ref(x, 2, prec)
2560    }
2561}
2562
2563impl Csc for Float {
2564    type Output = Self;
2565
2566    /// Computes $\csc x$, the cosecant of a [`Float`], taking it by value.
2567    ///
2568    /// If the output has a precision, it is the precision of the input. If the cosecant is
2569    /// equidistant from two [`Float`]s with the specified precision, the [`Float`] with fewer 1s in
2570    /// its binary expansion is chosen. See [`RoundingMode`] for a description of the `Nearest`
2571    /// rounding mode.
2572    ///
2573    /// $$
2574    /// f(x) = \csc x+\varepsilon.
2575    /// $$
2576    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
2577    /// - If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p}$, where $p$ is
2578    ///   the precision of the input.
2579    ///
2580    /// Special cases:
2581    /// - $f(\text{NaN})=\text{NaN}$
2582    /// - $f(\pm\infty)=\text{NaN}$
2583    /// - $f(\pm0.0)=\pm\infty$
2584    ///
2585    /// See the [`Float::csc_round`] documentation for information on overflow.
2586    ///
2587    /// If you want to use a rounding mode other than `Nearest`, consider using [`Float::csc_round`]
2588    /// instead. If you want to specify the output precision, consider using [`Float::csc_prec`]. If
2589    /// you want both of these things, consider using [`Float::csc_prec_round`].
2590    ///
2591    /// # Worst-case complexity
2592    /// $T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$
2593    ///
2594    /// $M(n, e) = O((n+e) \log (n+e))$
2595    ///
2596    /// where $T$ is time, $M$ is additional memory, $n$ is `self.significant_bits()`, and $e$ is
2597    /// the exponent of `self` (0 if `self` has no exponent or a negative one): the Taylor series at
2598    /// working precision $n$, summed by binary splitting for large $n$, costs the first term, and
2599    /// for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n +
2600    /// e$ bits. Unlike most functions, `csc` therefore gets slower as the magnitude of its input
2601    /// grows, not just as the precision does.
2602    ///
2603    /// # Examples
2604    /// ```
2605    /// use malachite_base::num::arithmetic::traits::Csc;
2606    /// use malachite_base::num::basic::traits::*;
2607    /// use malachite_float::Float;
2608    ///
2609    /// assert!(Float::NAN.csc().is_nan());
2610    /// assert!(Float::INFINITY.csc().is_nan());
2611    /// assert!(Float::NEGATIVE_INFINITY.csc().is_nan());
2612    /// assert_eq!(Float::ZERO.csc().to_string(), "Infinity");
2613    /// assert_eq!(Float::NEGATIVE_ZERO.csc().to_string(), "-Infinity");
2614    /// assert_eq!(
2615    ///     Float::from_unsigned_prec(1u32, 100).0.csc().to_string(),
2616    ///     "1.1883951057781212162615994523744"
2617    /// );
2618    /// assert_eq!(
2619    ///     Float::from_unsigned_prec(100u32, 100).0.csc().to_string(),
2620    ///     "-1.9748575314240999612122645488016"
2621    /// );
2622    /// ```
2623    #[inline]
2624    fn csc(self) -> Self {
2625        let prec = self.significant_bits();
2626        self.csc_prec_round(prec, Nearest).0
2627    }
2628}
2629
2630impl Csc for &Float {
2631    type Output = Float;
2632
2633    /// Computes $\csc x$, the cosecant of a [`Float`], taking it by reference.
2634    ///
2635    /// If the output has a precision, it is the precision of the input. If the cosecant is
2636    /// equidistant from two [`Float`]s with the specified precision, the [`Float`] with fewer 1s in
2637    /// its binary expansion is chosen. See [`RoundingMode`] for a description of the `Nearest`
2638    /// rounding mode.
2639    ///
2640    /// $$
2641    /// f(x) = \csc x+\varepsilon.
2642    /// $$
2643    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
2644    /// - If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p}$, where $p$ is
2645    ///   the precision of the input.
2646    ///
2647    /// Special cases:
2648    /// - $f(\text{NaN})=\text{NaN}$
2649    /// - $f(\pm\infty)=\text{NaN}$
2650    /// - $f(\pm0.0)=\pm\infty$
2651    ///
2652    /// See the [`Float::csc_round`] documentation for information on overflow.
2653    ///
2654    /// If you want to use a rounding mode other than `Nearest`, consider using
2655    /// [`Float::csc_round_ref`] instead. If you want to specify the output precision, consider
2656    /// using [`Float::csc_prec_ref`]. If you want both of these things, consider using
2657    /// [`Float::csc_prec_round_ref`].
2658    ///
2659    /// # Worst-case complexity
2660    /// $T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$
2661    ///
2662    /// $M(n, e) = O((n+e) \log (n+e))$
2663    ///
2664    /// where $T$ is time, $M$ is additional memory, $n$ is `self.significant_bits()`, and $e$ is
2665    /// the exponent of `self` (0 if `self` has no exponent or a negative one): the Taylor series at
2666    /// working precision $n$, summed by binary splitting for large $n$, costs the first term, and
2667    /// for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n +
2668    /// e$ bits. Unlike most functions, `csc` therefore gets slower as the magnitude of its input
2669    /// grows, not just as the precision does.
2670    ///
2671    /// # Examples
2672    /// ```
2673    /// use malachite_base::num::arithmetic::traits::Csc;
2674    /// use malachite_base::num::basic::traits::*;
2675    /// use malachite_float::Float;
2676    ///
2677    /// assert!(Float::NAN.csc().is_nan());
2678    /// assert!(Float::INFINITY.csc().is_nan());
2679    /// assert!(Float::NEGATIVE_INFINITY.csc().is_nan());
2680    /// assert_eq!(Float::ZERO.csc().to_string(), "Infinity");
2681    /// assert_eq!(Float::NEGATIVE_ZERO.csc().to_string(), "-Infinity");
2682    /// assert_eq!(
2683    ///     (&Float::from_unsigned_prec(1u32, 100).0).csc().to_string(),
2684    ///     "1.1883951057781212162615994523744"
2685    /// );
2686    /// assert_eq!(
2687    ///     (&Float::from_unsigned_prec(100u32, 100).0)
2688    ///         .csc()
2689    ///         .to_string(),
2690    ///     "-1.9748575314240999612122645488016"
2691    /// );
2692    /// ```
2693    #[inline]
2694    fn csc(self) -> Float {
2695        self.csc_prec_round_ref(self.significant_bits(), Nearest).0
2696    }
2697}
2698
2699impl CscAssign for Float {
2700    /// Computes $\csc x$, the cosecant of a [`Float`], in place.
2701    ///
2702    /// If the output has a precision, it is the precision of the input. If the cosecant is
2703    /// equidistant from two [`Float`]s with the specified precision, the [`Float`] with fewer 1s in
2704    /// its binary expansion is chosen. See [`RoundingMode`] for a description of the `Nearest`
2705    /// rounding mode.
2706    ///
2707    /// $$
2708    /// x \gets \csc x+\varepsilon.
2709    /// $$
2710    /// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
2711    /// - If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p}$, where $p$ is
2712    ///   the precision of the input.
2713    ///
2714    /// See the [`Float::csc`] documentation for information on special cases and overflow.
2715    ///
2716    /// If you want to use a rounding mode other than `Nearest`, consider using
2717    /// [`Float::csc_round_assign`] instead. If you want to specify the output precision, consider
2718    /// using [`Float::csc_prec_assign`]. If you want both of these things, consider using
2719    /// [`Float::csc_prec_round_assign`].
2720    ///
2721    /// # Worst-case complexity
2722    /// $T(n, e) = O(n (\log n)^3 \log\log n + (n+e) (\log (n+e))^2 \log\log (n+e))$
2723    ///
2724    /// $M(n, e) = O((n+e) \log (n+e))$
2725    ///
2726    /// where $T$ is time, $M$ is additional memory, $n$ is `self.significant_bits()`, and $e$ is
2727    /// the exponent of `self` (0 if `self` has no exponent or a negative one): the Taylor series at
2728    /// working precision $n$, summed by binary splitting for large $n$, costs the first term, and
2729    /// for $|x| \geq 4$ the argument is reduced modulo $2\pi$, which requires $\pi$ to about $n +
2730    /// e$ bits. Unlike most functions, `csc` therefore gets slower as the magnitude of its input
2731    /// grows, not just as the precision does.
2732    ///
2733    /// # Examples
2734    /// ```
2735    /// use malachite_base::num::arithmetic::traits::CscAssign;
2736    /// use malachite_base::num::basic::traits::*;
2737    /// use malachite_float::Float;
2738    ///
2739    /// let mut x = Float::NAN;
2740    /// x.csc_assign();
2741    /// assert!(x.is_nan());
2742    ///
2743    /// let mut x = Float::INFINITY;
2744    /// x.csc_assign();
2745    /// assert!(x.is_nan());
2746    ///
2747    /// let mut x = Float::NEGATIVE_INFINITY;
2748    /// x.csc_assign();
2749    /// assert!(x.is_nan());
2750    ///
2751    /// let mut x = Float::ZERO;
2752    /// x.csc_assign();
2753    /// assert_eq!(x.to_string(), "Infinity");
2754    ///
2755    /// let mut x = Float::NEGATIVE_ZERO;
2756    /// x.csc_assign();
2757    /// assert_eq!(x.to_string(), "-Infinity");
2758    ///
2759    /// let mut x = Float::from_unsigned_prec(1u32, 100).0;
2760    /// x.csc_assign();
2761    /// assert_eq!(x.to_string(), "1.1883951057781212162615994523744");
2762    ///
2763    /// let mut x = Float::from_unsigned_prec(100u32, 100).0;
2764    /// x.csc_assign();
2765    /// assert_eq!(x.to_string(), "-1.9748575314240999612122645488016");
2766    /// ```
2767    #[inline]
2768    fn csc_assign(&mut self) {
2769        let prec = self.significant_bits();
2770        self.csc_prec_round_assign(prec, Nearest);
2771    }
2772}
2773
2774/// Computes $\csc x$, the cosecant of a primitive float, correctly rounded. Neither the standard
2775/// library nor `libm` provides a cosecant.
2776///
2777/// $$
2778/// f(x) = \csc x+\varepsilon.
2779/// $$
2780/// - If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
2781/// - If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p}$, where $p$ is the
2782///   precision of the output (24 if `T` is a [`f32`] and 53 if `T` is a [`f64`]).
2783///
2784/// Special cases:
2785/// - $f(\text{NaN})=\text{NaN}$
2786/// - $f(\pm\infty)=\text{NaN}$
2787/// - $f(\pm0.0)=\pm\infty$
2788///
2789/// Overflow is possible: the cosecant of a tiny $x$ is close to $1/x$, so an $x$ with $|x|$ below
2790/// about $2^{-128}$ has a cosecant beyond the largest [`f32`], and one below about $2^{-1024}$
2791/// beyond the largest [`f64`]; the result is then $\pm\infty$. No [`f32`] or [`f64`] is close
2792/// enough to a nonzero multiple of $\pi$ for its cosecant to overflow, and the result is never
2793/// subnormal, since $|\csc x| \geq 1$.
2794///
2795/// # Worst-case complexity
2796/// Constant time and additional memory.
2797///
2798/// # Examples
2799/// ```
2800/// use malachite_base::num::basic::traits::NegativeInfinity;
2801/// use malachite_base::num::float::NiceFloat;
2802/// use malachite_float::float::arithmetic::csc::primitive_float_csc;
2803///
2804/// assert!(primitive_float_csc(f32::NAN).is_nan());
2805/// assert!(primitive_float_csc(f32::INFINITY).is_nan());
2806/// assert!(primitive_float_csc(f32::NEGATIVE_INFINITY).is_nan());
2807/// assert_eq!(
2808///     NiceFloat(primitive_float_csc(0.0f32)),
2809///     NiceFloat(f32::INFINITY)
2810/// );
2811/// assert_eq!(
2812///     NiceFloat(primitive_float_csc(-0.0f32)),
2813///     NiceFloat(f32::NEGATIVE_INFINITY)
2814/// );
2815/// assert_eq!(NiceFloat(primitive_float_csc(1.0f32)), NiceFloat(1.1883951));
2816/// assert_eq!(
2817///     NiceFloat(primitive_float_csc(1.0f64)),
2818///     NiceFloat(1.1883951057781212)
2819/// );
2820/// ```
2821#[inline]
2822#[allow(clippy::type_repetition_in_bounds)]
2823pub fn primitive_float_csc<T: PrimitiveFloat>(x: T) -> T
2824where
2825    Float: From<T> + PartialOrd<T>,
2826    for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
2827{
2828    emulate_float_to_float_fn(Float::csc_prec, x)
2829}
2830
2831/// Computes $\csc x$, the cosecant of a [`Rational`], returning the result as a primitive float.
2832///
2833/// $$
2834/// f(x) = \csc x+\varepsilon,
2835/// $$
2836/// where $|\varepsilon| < 2^{\lfloor\log_2 |\csc x|\rfloor-p}$, and $p$ is the precision of the
2837/// output (24 if `T` is a [`f32`] and 53 if `T` is a [`f64`]).
2838///
2839/// Special cases:
2840/// - $f(0)=\infty$
2841///
2842/// Overflow is possible: a [`Rational`] within about $2^{-129}$ of a nonzero multiple of $\pi$ has
2843/// a cosecant beyond the largest [`f32`], and one within about $2^{-1025}$ of one beyond the
2844/// largest [`f64`]; so does any [`Rational`] small enough that its reciprocal alone leaves the
2845/// range, and $0$ itself, whose cosecant is $\infty$. Underflow is not possible, since $|\csc x|
2846/// \geq 1$.
2847///
2848/// # Worst-case complexity
2849/// $T(m, e) = O((m+e) (\log (m+e))^2 \log\log (m+e))$
2850///
2851/// $M(m, e) = O((m+e) \log (m+e))$
2852///
2853/// where $T$ is time, $M$ is additional memory, $m$ is `x.significant_bits()`, and $e$ is
2854/// `x.floor_log_base_2_abs()` (taken as 0 when it is negative or $x = 0$): for $|x| \geq 3$ the
2855/// argument is reduced modulo $2\pi$, which needs $\pi$ to about $e$ bits.
2856///
2857/// # Examples
2858/// ```
2859/// use malachite_base::num::basic::traits::Zero;
2860/// use malachite_base::num::float::NiceFloat;
2861/// use malachite_float::float::arithmetic::csc::primitive_float_csc_rational;
2862/// use malachite_q::Rational;
2863///
2864/// assert_eq!(
2865///     NiceFloat(primitive_float_csc_rational::<f64>(&Rational::ZERO)),
2866///     NiceFloat(f64::INFINITY)
2867/// );
2868/// assert_eq!(
2869///     NiceFloat(primitive_float_csc_rational::<f64>(
2870///         &Rational::from_unsigneds(1u8, 3)
2871///     )),
2872///     NiceFloat(3.0562842545795195)
2873/// );
2874/// assert_eq!(
2875///     NiceFloat(primitive_float_csc_rational::<f32>(
2876///         &Rational::from_unsigneds(1u8, 3)
2877///     )),
2878///     NiceFloat(3.0562842)
2879/// );
2880/// assert_eq!(
2881///     NiceFloat(primitive_float_csc_rational::<f64>(&Rational::from(10000))),
2882///     NiceFloat(-3.2720972452826818)
2883/// );
2884/// ```
2885#[inline]
2886#[allow(clippy::type_repetition_in_bounds)]
2887pub fn primitive_float_csc_rational<T: PrimitiveFloat>(x: &Rational) -> T
2888where
2889    Float: PartialOrd<T>,
2890    for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
2891{
2892    emulate_rational_to_float_fn(Float::csc_rational_prec_ref, x)
2893}
2894
2895/// Computes $\csc(2\pi x/u)$, the cosecant of a primitive float measured in $u$ths of a turn (so
2896/// that `u = 360` is degrees).
2897///
2898/// $$
2899/// f(x,u) = \csc(2\pi x/u)+\varepsilon.
2900/// $$
2901/// - If $x$ is not finite, $u=0$, or $x/u$ is a multiple of $1/4$ or has denominator 12 in lowest
2902///   terms, $\varepsilon$ may be ignored or assumed to be 0.
2903/// - Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |\csc(2\pi x/u)|\rfloor-p}$, where $p$ is the
2904///   precision of the output (24 if `T` is a [`f32`] and 53 if `T` is a [`f64`]).
2905///
2906/// Special cases:
2907/// - $f(\text{NaN},u)=\text{NaN}$
2908/// - $f(\pm\infty,u)=\text{NaN}$
2909/// - $f(x,0)=\text{NaN}$
2910/// - $f(\pm0.0,u)=\pm\infty$
2911/// - If $x/u$ is a multiple of $1/2$, the cosecant has a pole there, and the result is exactly
2912///   $\pm\infty$ with the sign of $x$: the sine is a zero carrying that sign, and the cosecant is
2913///   its reciprocal, which keeps the function odd.
2914/// - If $x/u$ in lowest terms has denominator 4, the result is exactly $\pm1$, and if it has
2915///   denominator 12, exactly $\pm2$.
2916/// - If $x/u$ in lowest terms has denominator 3 or 6, the result is $\pm2\sqrt3/3$; if 8,
2917///   $\pm\sqrt2$; and if 20, $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the golden
2918///   ratio.
2919///
2920/// Overflow happens at a pole, where the result is exactly $\pm\infty$, and for a tiny $x/u$, whose
2921/// cosecant is close to $u/(2\pi x)$: an [`f32`] or [`f64`] whose fraction of a turn is not a
2922/// multiple of $1/2$ is more than $2^{-66}$ of a turn away from one, so a cosecant that is not a
2923/// pole stays below $2^{64}$ unless the angle itself is tiny. Underflow is not possible, since
2924/// $|\csc(2\pi x/u)| \geq 1$.
2925///
2926/// # Worst-case complexity
2927/// Constant time and additional memory.
2928///
2929/// # Examples
2930/// ```
2931/// use malachite_base::num::basic::traits::NegativeInfinity;
2932/// use malachite_base::num::float::NiceFloat;
2933/// use malachite_float::float::arithmetic::csc::primitive_float_csc_with_period;
2934///
2935/// assert!(primitive_float_csc_with_period(f32::NAN, 360).is_nan());
2936/// assert!(primitive_float_csc_with_period(f32::INFINITY, 360).is_nan());
2937/// assert!(primitive_float_csc_with_period(f32::NEGATIVE_INFINITY, 360).is_nan());
2938/// assert!(primitive_float_csc_with_period(1.0f32, 0).is_nan());
2939/// assert_eq!(
2940///     NiceFloat(primitive_float_csc_with_period(-0.0f32, 360)),
2941///     NiceFloat(f32::NEGATIVE_INFINITY)
2942/// );
2943/// // a quarter turn is exactly 1
2944/// assert_eq!(
2945///     NiceFloat(primitive_float_csc_with_period(90.0f32, 360)),
2946///     NiceFloat(1.0)
2947/// );
2948/// // a half turn is a pole
2949/// assert_eq!(
2950///     NiceFloat(primitive_float_csc_with_period(180.0f32, 360)),
2951///     NiceFloat(f32::INFINITY)
2952/// );
2953/// // a sixth of a turn: 2 sqrt(3)/3
2954/// assert_eq!(
2955///     NiceFloat(primitive_float_csc_with_period(60.0f32, 360)),
2956///     NiceFloat(1.1547005)
2957/// );
2958/// // a twelfth of a turn is exactly 2
2959/// assert_eq!(
2960///     NiceFloat(primitive_float_csc_with_period(30.0f64, 360)),
2961///     NiceFloat(2.0)
2962/// );
2963/// assert_eq!(
2964///     NiceFloat(primitive_float_csc_with_period(1.0f32, 7)),
2965///     NiceFloat(1.279048)
2966/// );
2967/// assert_eq!(
2968///     NiceFloat(primitive_float_csc_with_period(1.0f64, 7)),
2969///     NiceFloat(1.2790480076899327)
2970/// );
2971/// ```
2972#[inline]
2973#[allow(clippy::type_repetition_in_bounds)]
2974pub fn primitive_float_csc_with_period<T: PrimitiveFloat>(x: T, u: u64) -> T
2975where
2976    Float: From<T> + PartialOrd<T>,
2977    for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
2978{
2979    emulate_float_to_float_fn(|x, prec| Float::csc_with_period_prec(x, u, prec), x)
2980}
2981
2982/// Computes $\csc(2\pi x/u)$, the cosecant of a [`Rational`] measured in $u$ths of a turn (so that
2983/// `u = 360` is degrees), returning the result as a primitive float.
2984///
2985/// $$
2986/// f(x,u) = \csc(2\pi x/u)+\varepsilon.
2987/// $$
2988/// - If $u=0$ or $x/u$ is a multiple of $1/4$ or has denominator 12 in lowest terms, $\varepsilon$
2989///   may be ignored or assumed to be 0.
2990/// - Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |\csc(2\pi x/u)|\rfloor-p}$, where $p$ is the
2991///   precision of the output (24 if `T` is a [`f32`] and 53 if `T` is a [`f64`]).
2992///
2993/// Special cases:
2994/// - $f(x,0)=\text{NaN}$
2995/// - $f(0,u)=\infty$
2996/// - If $x/u$ is a multiple of $1/2$, the cosecant has a pole there, and the result is exactly
2997///   $\pm\infty$ with the sign of $x$: the sine is a zero carrying that sign, and the cosecant is
2998///   its reciprocal, which keeps the function odd.
2999/// - If $x/u$ in lowest terms has denominator 4, the result is exactly $\pm1$, and if it has
3000///   denominator 12, exactly $\pm2$.
3001/// - If $x/u$ in lowest terms has denominator 3 or 6, the result is $\pm2\sqrt3/3$; if 8,
3002///   $\pm\sqrt2$; and if 20, $\pm2\varphi$ or $\pm2(\varphi-1)$, where $\varphi$ is the golden
3003///   ratio.
3004///
3005/// Overflow is possible away from a pole too: a fraction of a turn within about $2^{-130}$ of a
3006/// multiple of $1/2$ has a cosecant beyond the largest [`f32`], and one within about $2^{-1026}$ of
3007/// one beyond the largest [`f64`]; so does a fraction of a turn small enough on its own, which a
3008/// [`Rational`] can be however large its denominator is not. The result is then $\pm\infty$.
3009/// Underflow is not possible, since $|\csc(2\pi x/u)| \geq 1$.
3010///
3011/// # Worst-case complexity
3012/// $T(m) = O(m (\log m)^2 \log\log m)$
3013///
3014/// $M(m) = O(m \log m)$
3015///
3016/// where $T$ is time, $M$ is additional memory, and $m$ is `x.significant_bits()`: the fraction of
3017/// a turn is reduced modulo 1 exactly, so the magnitude of $x$ does not drive the cost.
3018///
3019/// # Examples
3020/// ```
3021/// use malachite_base::num::basic::traits::Zero;
3022/// use malachite_base::num::float::NiceFloat;
3023/// use malachite_float::float::arithmetic::csc::primitive_float_csc_with_period_rational;
3024/// use malachite_q::Rational;
3025///
3026/// assert!(primitive_float_csc_with_period_rational::<f64>(&Rational::ZERO, 0).is_nan());
3027/// assert_eq!(
3028///     NiceFloat(primitive_float_csc_with_period_rational::<f64>(
3029///         &Rational::ZERO,
3030///         360
3031///     )),
3032///     NiceFloat(f64::INFINITY)
3033/// );
3034/// // a quarter turn is exactly 1
3035/// assert_eq!(
3036///     NiceFloat(primitive_float_csc_with_period_rational::<f64>(
3037///         &Rational::from_unsigneds(1u8, 4),
3038///         1
3039///     )),
3040///     NiceFloat(1.0)
3041/// );
3042/// // an eighth of a turn: sqrt(2)
3043/// assert_eq!(
3044///     NiceFloat(primitive_float_csc_with_period_rational::<f64>(
3045///         &Rational::from_unsigneds(1u8, 8),
3046///         1
3047///     )),
3048///     NiceFloat(core::f64::consts::SQRT_2)
3049/// );
3050/// // a twelfth of a turn is exactly 2
3051/// assert_eq!(
3052///     NiceFloat(primitive_float_csc_with_period_rational::<f64>(
3053///         &Rational::from_unsigneds(1u8, 12),
3054///         1
3055///     )),
3056///     NiceFloat(2.0)
3057/// );
3058/// assert_eq!(
3059///     NiceFloat(primitive_float_csc_with_period_rational::<f32>(
3060///         &Rational::from_unsigneds(1u8, 7),
3061///         1
3062///     )),
3063///     NiceFloat(1.279048)
3064/// );
3065/// assert_eq!(
3066///     NiceFloat(primitive_float_csc_with_period_rational::<f64>(
3067///         &Rational::from_unsigneds(1u8, 7),
3068///         1
3069///     )),
3070///     NiceFloat(1.2790480076899327)
3071/// );
3072/// ```
3073#[inline]
3074#[allow(clippy::type_repetition_in_bounds)]
3075pub fn primitive_float_csc_with_period_rational<T: PrimitiveFloat>(x: &Rational, u: u64) -> T
3076where
3077    Float: PartialOrd<T>,
3078    for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
3079{
3080    emulate_rational_to_float_fn(
3081        |x, prec| Float::csc_with_period_rational_prec_ref(x, u, prec),
3082        x,
3083    )
3084}
3085
3086/// Computes $\csc(\pi x)$, the cosecant of a primitive float measured in half-turns.
3087///
3088/// This is `primitive_float_csc_with_period` with a period of 2: see
3089/// [`primitive_float_csc_with_period`] for the error bound and the special cases, with $u = 2$.
3090/// Integers are poles and give exactly $\pm\infty$ with the sign of $x$; half-integers give exactly
3091/// $\pm1$; odd multiples of $1/6$ give exactly $\pm2$; odd multiples of $1/4$ give $\pm\sqrt2$; and
3092/// multiples of $1/3$ that are not integers give $\pm2\sqrt3/3$.
3093///
3094/// # Worst-case complexity
3095/// Constant time and additional memory.
3096///
3097/// # Examples
3098/// ```
3099/// use malachite_base::num::float::NiceFloat;
3100/// use malachite_float::float::arithmetic::csc::primitive_float_csc_pi;
3101///
3102/// assert!(primitive_float_csc_pi(f32::NAN).is_nan());
3103/// // a half-integer is exactly 1
3104/// assert_eq!(NiceFloat(primitive_float_csc_pi(0.5f32)), NiceFloat(1.0));
3105/// // an integer is a pole
3106/// assert_eq!(
3107///     NiceFloat(primitive_float_csc_pi(1.0f64)),
3108///     NiceFloat(f64::INFINITY)
3109/// );
3110/// // an odd multiple of a quarter: sqrt(2)
3111/// assert_eq!(
3112///     NiceFloat(primitive_float_csc_pi(0.25f32)),
3113///     NiceFloat(core::f32::consts::SQRT_2)
3114/// );
3115/// assert_eq!(
3116///     NiceFloat(primitive_float_csc_pi(0.1f32)),
3117///     NiceFloat(3.236068)
3118/// );
3119/// assert_eq!(
3120///     NiceFloat(primitive_float_csc_pi(0.1f64)),
3121///     NiceFloat(3.2360679774997894)
3122/// );
3123/// ```
3124#[inline]
3125#[allow(clippy::type_repetition_in_bounds)]
3126pub fn primitive_float_csc_pi<T: PrimitiveFloat>(x: T) -> T
3127where
3128    Float: From<T> + PartialOrd<T>,
3129    for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
3130{
3131    primitive_float_csc_with_period(x, 2)
3132}
3133
3134/// Computes $\csc(\pi x)$, the cosecant of a [`Rational`] measured in half-turns, returning the
3135/// result as a primitive float.
3136///
3137/// This is `primitive_float_csc_with_period_rational` with a period of 2: see
3138/// [`primitive_float_csc_with_period_rational`] for the error bound, the special cases, and the
3139/// complexity, with $u = 2$.
3140///
3141/// # Worst-case complexity
3142/// $T(m) = O(m (\log m)^2 \log\log m)$
3143///
3144/// $M(m) = O(m \log m)$
3145///
3146/// where $T$ is time, $M$ is additional memory, and $m$ is `x.significant_bits()`.
3147///
3148/// # Examples
3149/// ```
3150/// use malachite_base::num::basic::traits::OneHalf;
3151/// use malachite_base::num::float::NiceFloat;
3152/// use malachite_float::float::arithmetic::csc::primitive_float_csc_pi_rational;
3153/// use malachite_q::Rational;
3154///
3155/// // a half of a half-turn is exactly 1
3156/// assert_eq!(
3157///     NiceFloat(primitive_float_csc_pi_rational::<f64>(&Rational::ONE_HALF)),
3158///     NiceFloat(1.0)
3159/// );
3160/// // a sixth of a half-turn is exactly 2
3161/// assert_eq!(
3162///     NiceFloat(primitive_float_csc_pi_rational::<f64>(
3163///         &Rational::from_unsigneds(1u8, 6)
3164///     )),
3165///     NiceFloat(2.0)
3166/// );
3167/// assert_eq!(
3168///     NiceFloat(primitive_float_csc_pi_rational::<f64>(
3169///         &Rational::from_unsigneds(1u8, 7)
3170///     )),
3171///     NiceFloat(2.3047648709624866)
3172/// );
3173/// ```
3174#[inline]
3175#[allow(clippy::type_repetition_in_bounds)]
3176pub fn primitive_float_csc_pi_rational<T: PrimitiveFloat>(x: &Rational) -> T
3177where
3178    Float: PartialOrd<T>,
3179    for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
3180{
3181    primitive_float_csc_with_period_rational(x, 2)
3182}