malachite_float/float/arithmetic/acsc.rs
1// Copyright © 2026 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::Float;
10use crate::InnerFloat::{Finite, Infinity, NaN, Zero};
11use crate::float::MAX_EXPONENT_I64;
12use crate::float::arithmetic::atan::{arc_with_period_scale, scaled_unsigned};
13use crate::float::arithmetic::round_near_x::{round_from_below, value_is_tie};
14use crate::float::arithmetic::sin::{SCALE, SCALE_I64, SCALED_INPUT_EXPONENT, scaled_underflow};
15use crate::{emulate_float_to_float_fn, emulate_rational_to_float_fn};
16use core::cmp::Ordering::{self, Equal, Greater, Less};
17use core::cmp::max;
18use malachite_base::num::arithmetic::traits::{
19 Abs, Acsc, AcscAssign, Atan, CeilingLogBase2, IsPowerOf2, PowerOf2, Reciprocal, Square,
20};
21use malachite_base::num::basic::floats::PrimitiveFloat;
22use malachite_base::num::basic::integers::PrimitiveInt;
23use malachite_base::num::basic::traits::{NaN as NaNTrait, NegativeZero, One, Zero as ZeroTrait};
24use malachite_base::num::comparison::traits::PartialOrdAbs;
25use malachite_base::num::conversion::traits::{ExactFrom, RoundingFrom};
26use malachite_base::num::logic::traits::SignificantBits;
27use malachite_base::rounding_modes::RoundingMode::{self, Exact, Nearest, Up};
28use malachite_nz::natural::arithmetic::float::round::float_can_round;
29use malachite_nz::platform::Limb;
30use malachite_q::Rational;
31
32// acsc(1) = pi/2 and acsc(-1) = -pi/2, neither of them representable. The arccosecant being odd,
33// the sign is stripped and restored with the rounding mode reflected along with it.
34pub(crate) fn signed_half_pi(negative: bool, prec: u64, rm: RoundingMode) -> (Float, Ordering) {
35 let (pi, o) = Float::pi_prec_round(prec, if negative { -rm } else { rm });
36 // exact
37 let half = pi >> 1u32;
38 if negative {
39 (-half, o.reverse())
40 } else {
41 (half, o)
42 }
43}
44
45// Computes acsc(|x|) for a finite `Float` x with |x| > 1, rounded to precision `prec` with rounding
46// mode `rm`. The caller restores the sign, the arccosecant being odd.
47//
48// MPFR has no arccosecant. Rather than take asin(1/x), which would round the reciprocal first and
49// pay for it -- the arcsine is not Lipschitz at 1, and 1/x lands there exactly when x is near +-1,
50// where about half the bits of the reciprocal would be lost -- the identity is used in the form
51//
52// acsc(x) = atan(1/sqrt(x^2 - 1))
53//
54// for a positive x. The subtraction x^2 - 1 is where an x near 1 loses bits, and it is done at a
55// precision wide enough to be exact: the square of a p-bit `Float` needs 2p bits, and their
56// difference no more. So nothing is lost, and the cost does not grow as x approaches +-1. The
57// reciprocal and the square root are taken together, by one correctly rounded `reciprocal_sqrt`.
58fn acsc_abs_prec_round(x: &Float, prec: u64, rm: RoundingMode) -> (Float, Ordering) {
59 let exp_x = i64::from(x.get_exponent().unwrap());
60 // acsc(x) = (1/x)(1 + 1/(6x^2) + ...), so once 2 EXP(x) is past the target precision the
61 // acsc(x) = (1/x)(1 + 1/(6x^2) + ...), a relative correction below 2^(-2 EXP(x) - 2). Once that
62 // is below the distance from 1/|x| to the nearest midpoint of the target precision -- which for
63 // a p-bit x is at least a relative 2^(-prec - p - 1) -- the reciprocal's own rounding is the
64 // answer, bar the exactly-representable and tie cases handled below. It has to be settled here
65 // rather than in the loop, for two reasons. The loop cannot certify an exactly representable
66 // result at all -- `float_can_round` refuses one -- so it would balloon toward 2 EXP(x) bits,
67 // billions of them for an extreme exponent, and a reciprocal taken at such a precision falls
68 // out of the exponent range and flushes to zero. And past 3 EXP(x) > MAX_EXPONENT the cubic
69 // term of the arctangent below underflows, so the arctangent stops moving and the loop exits
70 // reporting atan's side of 1/|x| -- the opposite of acsc's, the two corrections having opposite
71 // signs. Keeping the test off the working precision also keeps the square below from
72 // overflowing.
73 if exp_x << 1 > MAX_EXPONENT_I64
74 || exp_x << 1 > i64::exact_from(prec + x.get_prec().unwrap()) + 4
75 {
76 let a = x.abs();
77 let tie = rm == Nearest && {
78 let (wide, o_wide) = a.reciprocal_prec_ref(prec + 1);
79 value_is_tie(&wide, o_wide, prec)
80 };
81 let (t, o) = a.reciprocal_prec_round(prec, rm);
82 return round_from_below(t, o, tie, rm);
83 }
84 // the width at which x^2 - 1 is exact
85 let exact_w = (x.get_prec().unwrap() << 1) + 2;
86 let mut w = prec + prec.ceiling_log_base_2() + 10;
87 let mut increment = Limb::WIDTH;
88 loop {
89 let q = x
90 .square_prec_ref(max(w, exact_w))
91 .0
92 .sub_prec(Float::ONE, max(w, exact_w))
93 .0
94 .reciprocal_sqrt_prec(w)
95 .0;
96 // The reciprocal square root is correctly rounded and the arctangent neither amplifies a
97 // relative error nor adds more than its own half ulp, so three bits of slack suffice.
98 let t = q.atan();
99 if float_can_round(t.significand_ref().unwrap(), w - 3, prec, rm) {
100 return Float::from_float_prec_round(t, prec, rm);
101 }
102 w += increment;
103 increment = w >> 1;
104 }
105}
106
107// Computes acsc(x) for a finite nonzero `Float` x, rounded to precision `prec` with rounding mode
108// `rm`.
109fn acsc_prec_round_normal_ref(x: &Float, prec: u64, rm: RoundingMode) -> (Float, Ordering) {
110 let negative = *x < 0u32;
111 match x.partial_cmp_abs(&1u32).unwrap() {
112 // acsc(x) = NaN for |x| < 1, the cosecant never taking a value there
113 Less => (Float::NAN, Equal),
114 // acsc(1) = pi/2 and acsc(-1) = -pi/2
115 Equal => {
116 assert_ne!(rm, Exact, "Inexact acsc");
117 signed_half_pi(negative, prec, rm)
118 }
119 Greater => {
120 assert_ne!(rm, Exact, "Inexact acsc");
121 // the arccosecant is odd, so the sign is stripped and restored, the rounding mode
122 // reflected along with it
123 let (t, o) = acsc_abs_prec_round(x, prec, if negative { -rm } else { rm });
124 if negative { (-t, o.reverse()) } else { (t, o) }
125 }
126 }
127}
128
129// Computes acsc(x) for a nonzero `Rational` x with |x| > 1, rounded to precision `prec` with
130// rounding mode `rm`.
131pub(crate) fn acsc_rational_helper(x: &Rational, prec: u64, rm: RoundingMode) -> (Float, Ordering) {
132 assert_ne!(rm, Exact, "Inexact acsc_rational");
133 let negative = *x < 0u32;
134 let rm = if negative { -rm } else { rm };
135 let exp_x = x.floor_log_base_2_abs() + 1;
136 let xp = x.abs();
137 let mut w = prec + prec.ceiling_log_base_2() + 10;
138 let mut increment = Limb::WIDTH;
139 // acsc(x) = (1/|x|)(1 + O(x^-2)) for a large |x|. A `Rational` has no exponent bound, so it can
140 // be large enough to put that below the smallest positive `Float`, which the `Float`
141 // arccosecant cannot reach; there the correction is invisible at any working precision the loop
142 // can reach and the answer is 1/|x|, rounded. It is formed scaled up by 2^SCALE, and the
143 // underflow is then decided by the rounding mode alone.
144 if 1 - exp_x <= SCALED_INPUT_EXPONENT {
145 let scaled = Rational::power_of_2(SCALE_I64) / &xp;
146 loop {
147 // rounded away from zero, the side acsc(x) is on
148 let t = Float::from_rational_prec_round_ref(&scaled, w, Up).0;
149 // `rm` is already reflected, and the value here is the positive |acsc(x)|, so the
150 // underflow is decided on that side and the sign restored with it
151 if let Some((t, o)) = scaled_underflow(&t, true, prec, rm) {
152 return if negative { (-t, o.reverse()) } else { (t, o) };
153 }
154 let t = t >> SCALE;
155 if float_can_round(t.significand_ref().unwrap(), w - 2, prec, rm) {
156 let (t, o) = Float::from_float_prec_round(t, prec, rm);
157 return if negative { (-t, o.reverse()) } else { (t, o) };
158 }
159 w += increment;
160 increment = w >> 1;
161 }
162 }
163 // As in the `Float` case, the reciprocal alone is the answer once the relative correction
164 // 1/(6x^2) falls below the distance from 1/|x| to the nearest midpoint of the target precision,
165 // which for a numerator of n bits is at least a relative 2^(-prec - n - 1). This spares a huge
166 // `Rational` from being squared, and settles the exactly-representable and tie cases that the
167 // loop below could never certify.
168 if exp_x << 1 > MAX_EXPONENT_I64
169 || exp_x << 1 > i64::exact_from(prec + xp.numerator_ref().significant_bits()) + 4
170 {
171 let recip = (&xp).reciprocal();
172 let tie = rm == Nearest && {
173 let (wide, o_wide) = Float::from_rational_prec_ref(&recip, prec + 1);
174 value_is_tie(&wide, o_wide, prec)
175 };
176 let (t, o) = Float::from_rational_prec_round(recip, prec, rm);
177 let (t, o) = round_from_below(t, o, tie, rm);
178 return if negative { (-t, o.reverse()) } else { (t, o) };
179 }
180 let mut r = None;
181 loop {
182 // exact, and positive since |x| > 1
183 let r = r.get_or_insert_with(|| (&xp).square() - Rational::ONE);
184 let q = Float::reciprocal_sqrt_rational_prec_ref(r, w).0;
185 // The reciprocal square root is correctly rounded and the arctangent neither amplifies a
186 // relative error nor adds more than its own half ulp, so three bits of slack suffice.
187 let t = q.atan();
188 if float_can_round(t.significand_ref().unwrap(), w - 3, prec, rm) {
189 let (t, o) = Float::from_float_prec_round(t, prec, rm);
190 return if negative { (-t, o.reverse()) } else { (t, o) };
191 }
192 w += increment;
193 increment = w >> 1;
194 }
195}
196
197// Computes acsc(x) u/(2 pi) for a finite `Float` x with |x| >= 1, rounded to precision `prec` with
198// rounding mode `rm`.
199//
200// The exact cases are the arcsine's, seen through the reciprocal: |x| = 1 gives a quarter turn and
201// |x| = 2 gives a twelfth, where the arcsine has |x| = 1 and |x| = 1/2. The arccosecant is odd, so
202// each carries the sign of x.
203fn acsc_with_period_prec_round_normal_ref(
204 x: &Float,
205 u: u64,
206 prec: u64,
207 rm: RoundingMode,
208) -> (Float, Ordering) {
209 let positive = *x > 0u32;
210 let exp_x = i64::from(x.get_exponent().unwrap());
211 let power_of_2 = x.significand_ref().unwrap().is_power_of_2();
212 // |x| = 1: acscu(1, u) = u/4 and acscu(-1, u) = -u/4, both exact
213 if exp_x == 1 && power_of_2 {
214 return scaled_unsigned(u, 2, positive, prec, rm);
215 }
216 // acsc(+-2) = +-pi/6, so acscu(+-2, u) = +-u/12 is exact when u is a multiple of 3
217 if exp_x == 2 && power_of_2 && u.is_multiple_of(3) {
218 return scaled_unsigned(u / 3, 2, positive, prec, rm);
219 }
220 // Nothing else can be rounded exactly
221 assert_ne!(rm, Exact, "Inexact acsc_with_period");
222 arc_with_period_scale(
223 // scaling by a power of 2 is exact, and acsc(x) u 2^SCALE stays far below the top of the
224 // range, since |acsc x| <= pi/2 and u < 2^64. Rounding away from zero is what the
225 // arccosecant's large-x shortcut needs too, `Up` being its own reflection.
226 |w| x.acsc_prec_round_ref(w, Up).0 << SCALE,
227 u,
228 positive,
229 prec,
230 rm,
231 )
232}
233
234// Computes acsc(x) u/(2 pi) for a `Rational` x with |x| >= 1, rounded to precision `prec` with
235// rounding mode `rm`.
236pub(crate) fn acsc_with_period_rational_helper(
237 x: &Rational,
238 u: u64,
239 prec: u64,
240 rm: RoundingMode,
241) -> (Float, Ordering) {
242 let positive = *x > 0u32;
243 let exp_x = x.floor_log_base_2_abs() + 1;
244 let integer = x.denominator_ref() == &1u32;
245 // |x| = 1: acscu(1, u) = u/4 and acscu(-1, u) = -u/4, both exact
246 if integer && x.numerator_ref() == &1u32 {
247 return scaled_unsigned(u, 2, positive, prec, rm);
248 }
249 // acsc(+-2) = +-pi/6, so acscu(+-2, u) = +-u/12 is exact when u is a multiple of 3
250 if integer && x.numerator_ref() == &2u32 && u.is_multiple_of(3) {
251 return scaled_unsigned(u / 3, 2, positive, prec, rm);
252 }
253 // Nothing else can be rounded exactly
254 assert_ne!(rm, Exact, "Inexact acsc_with_period_rational");
255 // An |x| large enough to put acsc(x) = (1/x)(1 + O(x^-2)) below the smallest positive `Float`,
256 // where `acsc_rational_helper` would report an underflow -- but a large u can lift acsc(x) u/(2
257 // pi) back into the range, so the reciprocal, exact as a `Rational` and with the correction
258 // invisible at any reachable working precision, is taken here instead, scaled up by 2^SCALE for
259 // the quotient. It keeps the sign of x, the arccosecant being odd.
260 if 1 - exp_x <= SCALED_INPUT_EXPONENT {
261 let scaled = Rational::power_of_2(SCALE_I64) / x;
262 return arc_with_period_scale(
263 |w| Float::from_rational_prec_round_ref(&scaled, w, Up).0,
264 u,
265 positive,
266 prec,
267 rm,
268 );
269 }
270 arc_with_period_scale(
271 // scaling by a power of 2 is exact, and acsc(x) u 2^SCALE stays far below the top of the
272 // range, since |acsc x| <= pi/2 and u < 2^64
273 |w| acsc_rational_helper(x, w, Up).0 << SCALE,
274 u,
275 positive,
276 prec,
277 rm,
278 )
279}
280
281impl Float {
282 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], rounding the result to the
283 /// specified precision and with the specified rounding mode. The [`Float`] is taken by value.
284 /// An [`Ordering`] is also returned, indicating whether the rounded arccosecant is less than,
285 /// equal to, or greater than the exact arccosecant. Although `NaN`s are not comparable to any
286 /// [`Float`], whenever this function returns a `NaN` it also returns `Equal`.
287 ///
288 /// See [`RoundingMode`] for a description of the possible rounding modes.
289 ///
290 /// $$
291 /// f(x,p,m) = \operatorname{acsc}(x)+\varepsilon.
292 /// $$
293 /// - If $x$ is NaN, infinite, or $|x|<1$, $\varepsilon$ may be ignored or assumed to be 0.
294 /// - Otherwise, if $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2
295 /// |\operatorname{acsc}(x)|\rfloor-p+1}$.
296 /// - Otherwise, if $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2
297 /// |\operatorname{acsc}(x)|\rfloor-p}$.
298 ///
299 /// If the output has a precision, it is `prec`.
300 ///
301 /// Special cases:
302 /// - $f(\text{NaN},p,m)=\text{NaN}$
303 /// - $f(x,p,m)=\text{NaN}$ for $|x|<1$, including $\pm0.0$
304 /// - $f(\infty,p,m)=0.0$ and $f(-\infty,p,m)=-0.0$
305 /// - $f(1,p,m)=\pi/2$ and $f(-1,p,m)=-\pi/2$
306 ///
307 /// The infinities, and the inputs of magnitude below 1, are the only exact cases: $\pi/2$ is
308 /// never representable.
309 ///
310 /// The arccosecant is odd, so $f(-x,p,m)=-f(x,p,-m)$, with $-m$ the reflection of $m$ that
311 /// swaps `Floor` and `Ceiling`.
312 ///
313 /// Overflow is not possible, since $|\operatorname{acsc}(x)| \leq \pi/2$. Underflow is not
314 /// possible either: $|\operatorname{acsc}(x)|$ is about $1/|x|$ for a large $|x|$, and a
315 /// [`Float`]'s exponent is bounded, so the result stays above twice the smallest positive
316 /// [`Float`]. A [`Rational`] has no such bound; see [`Float::acsc_rational_prec_round`].
317 ///
318 /// If you know you'll be using `Nearest`, consider using [`Float::acsc_prec`] instead. If you
319 /// know that your target precision is the precision of the input, consider using
320 /// [`Float::acsc_round`] instead.
321 ///
322 /// # Worst-case complexity
323 /// $T(n, m) = O(n (\log n)^3 \log\log n + m \log m \log\log m)$
324 ///
325 /// $M(n, m) = O(n \log n + m \log m)$
326 ///
327 /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, and $m$ is
328 /// `self.significant_bits()`: the arccosecant is taken at a working precision of about $n$
329 /// bits, which costs the first term; the second is the exact square inside it. A large $x$
330 /// skips the square, its arccosecant being the arctangent of the reciprocal of $|x|$ to within
331 /// the working precision.
332 ///
333 /// # Panics
334 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
335 /// with the given precision.
336 ///
337 /// # Examples
338 /// ```
339 /// use malachite_base::num::basic::traits::{NegativeOne, Two};
340 /// use malachite_base::rounding_modes::RoundingMode::*;
341 /// use malachite_float::Float;
342 /// use std::cmp::Ordering::*;
343 ///
344 /// let (c, o) = Float::TWO.acsc_prec_round(10, Floor);
345 /// assert_eq!(c.to_string(), "0.52344");
346 /// assert_eq!(o, Less);
347 ///
348 /// let (c, o) = Float::TWO.acsc_prec_round(10, Ceiling);
349 /// assert_eq!(c.to_string(), "0.52441");
350 /// assert_eq!(o, Greater);
351 ///
352 /// // an input of -1 gives -pi/2
353 /// let (c, o) = Float::NEGATIVE_ONE.acsc_prec_round(10, Nearest);
354 /// assert_eq!(c.to_string(), "-1.5703");
355 /// assert_eq!(o, Greater);
356 /// ```
357 #[inline]
358 pub fn acsc_prec_round(self, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
359 self.acsc_prec_round_ref(prec, rm)
360 }
361
362 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], rounding the result to the
363 /// specified precision and with the specified rounding mode. The [`Float`] is taken by
364 /// reference. An [`Ordering`] is also returned, indicating whether the rounded arccosecant is
365 /// less than, equal to, or greater than the exact arccosecant. Although `NaN`s are not
366 /// comparable to any [`Float`], whenever this function returns a `NaN` it also returns `Equal`.
367 ///
368 /// See [`Float::acsc_prec_round`] for the error bounds, the special cases, and the complexity;
369 /// this function behaves the same way.
370 ///
371 /// # Panics
372 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
373 /// with the given precision.
374 ///
375 /// # Examples
376 /// ```
377 /// use malachite_base::num::basic::traits::{NegativeOne, Two};
378 /// use malachite_base::rounding_modes::RoundingMode::*;
379 /// use malachite_float::Float;
380 /// use std::cmp::Ordering::*;
381 ///
382 /// let (c, o) = (&Float::TWO).acsc_prec_round_ref(10, Floor);
383 /// assert_eq!(c.to_string(), "0.52344");
384 /// assert_eq!(o, Less);
385 ///
386 /// let (c, o) = (&Float::NEGATIVE_ONE).acsc_prec_round_ref(10, Nearest);
387 /// assert_eq!(c.to_string(), "-1.5703");
388 /// assert_eq!(o, Greater);
389 /// ```
390 pub fn acsc_prec_round_ref(&self, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
391 assert_ne!(prec, 0);
392 match &self.0 {
393 // the arccosecant is NaN inside (-1, 1), and both zeros are inside it
394 NaN | Zero { .. } => (Self::NAN, Equal),
395 // the cosecant falls to zero as its argument grows, so an infinite input gives a zero
396 // of the same sign -- exactly
397 Infinity { sign } => (
398 if *sign {
399 Self::ZERO
400 } else {
401 Self::NEGATIVE_ZERO
402 },
403 Equal,
404 ),
405 Finite { .. } => acsc_prec_round_normal_ref(self, prec, rm),
406 }
407 }
408
409 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], rounding the result to the
410 /// nearest value of the specified precision. The [`Float`] is taken by value. An [`Ordering`]
411 /// is also returned, indicating whether the rounded arccosecant is less than, equal to, or
412 /// greater than the exact arccosecant. Although `NaN`s are not comparable to any [`Float`],
413 /// whenever this function returns a `NaN` it also returns `Equal`.
414 ///
415 /// If the arccosecant is equidistant from two [`Float`]s with the specified precision, the
416 /// [`Float`] with fewer 1s in its binary expansion is chosen.
417 ///
418 /// See [`Float::acsc_prec_round`] for the error bounds, the special cases, and the complexity;
419 /// this function behaves the same way.
420 ///
421 /// If you want to use a rounding mode other than `Nearest`, consider using
422 /// [`Float::acsc_prec_round`] instead.
423 ///
424 /// # Panics
425 /// Panics if `prec` is zero.
426 ///
427 /// # Examples
428 /// ```
429 /// use malachite_base::num::basic::traits::Two;
430 /// use malachite_float::Float;
431 /// use std::cmp::Ordering::*;
432 ///
433 /// let (c, o) = Float::TWO.acsc_prec(10);
434 /// assert_eq!(c.to_string(), "0.52344");
435 /// assert_eq!(o, Less);
436 ///
437 /// let (c, o) = Float::from_unsigned_prec(2u32, 100).0.acsc_prec(100);
438 /// assert_eq!(c.to_string(), "0.52359877559829887307710723054682");
439 /// assert_eq!(o, Greater);
440 /// ```
441 #[inline]
442 pub fn acsc_prec(self, prec: u64) -> (Self, Ordering) {
443 self.acsc_prec_round(prec, Nearest)
444 }
445
446 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], rounding the result to the
447 /// nearest value of the specified precision. The [`Float`] is taken by reference. An
448 /// [`Ordering`] is also returned, indicating whether the rounded arccosecant is less than,
449 /// equal to, or greater than the exact arccosecant. Although `NaN`s are not comparable to any
450 /// [`Float`], whenever this function returns a `NaN` it also returns `Equal`.
451 ///
452 /// See [`Float::acsc_prec`] and [`Float::acsc_prec_round`]; this function behaves the same way.
453 ///
454 /// # Panics
455 /// Panics if `prec` is zero.
456 ///
457 /// # Examples
458 /// ```
459 /// use malachite_base::num::basic::traits::Two;
460 /// use malachite_float::Float;
461 /// use std::cmp::Ordering::*;
462 ///
463 /// let (c, o) = (&Float::TWO).acsc_prec_ref(10);
464 /// assert_eq!(c.to_string(), "0.52344");
465 /// assert_eq!(o, Less);
466 /// ```
467 #[inline]
468 pub fn acsc_prec_ref(&self, prec: u64) -> (Self, Ordering) {
469 self.acsc_prec_round_ref(prec, Nearest)
470 }
471
472 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], rounding the result with
473 /// the specified rounding mode. The precision of the output is the precision of the input. The
474 /// [`Float`] is taken by value. An [`Ordering`] is also returned, indicating whether the
475 /// rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although
476 /// `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN` it also
477 /// returns `Equal`.
478 ///
479 /// See [`Float::acsc_prec_round`] for the error bounds, the special cases, and the complexity;
480 /// this function behaves the same way, with `prec` the precision of the input.
481 ///
482 /// # Panics
483 /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
484 /// the input.
485 ///
486 /// # Examples
487 /// ```
488 /// use malachite_base::rounding_modes::RoundingMode::*;
489 /// use malachite_float::Float;
490 /// use std::cmp::Ordering::*;
491 ///
492 /// let x = Float::from_unsigned_prec(2u32, 100).0;
493 /// let (c, o) = x.acsc_round(Floor);
494 /// assert_eq!(c.to_string(), "0.52359877559829887307710723054603");
495 /// assert_eq!(o, Less);
496 /// ```
497 #[inline]
498 pub fn acsc_round(self, rm: RoundingMode) -> (Self, Ordering) {
499 let prec = self.significant_bits();
500 self.acsc_prec_round(prec, rm)
501 }
502
503 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], rounding the result with
504 /// the specified rounding mode. The precision of the output is the precision of the input. The
505 /// [`Float`] is taken by reference. An [`Ordering`] is also returned, indicating whether the
506 /// rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although
507 /// `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN` it also
508 /// returns `Equal`.
509 ///
510 /// See [`Float::acsc_round`] and [`Float::acsc_prec_round`]; this function behaves the same
511 /// way.
512 ///
513 /// # Panics
514 /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
515 /// the input.
516 ///
517 /// # Examples
518 /// ```
519 /// use malachite_base::rounding_modes::RoundingMode::*;
520 /// use malachite_float::Float;
521 /// use std::cmp::Ordering::*;
522 ///
523 /// let x = Float::from_unsigned_prec(2u32, 100).0;
524 /// let (c, o) = (&x).acsc_round_ref(Ceiling);
525 /// assert_eq!(c.to_string(), "0.52359877559829887307710723054682");
526 /// assert_eq!(o, Greater);
527 /// ```
528 #[inline]
529 pub fn acsc_round_ref(&self, rm: RoundingMode) -> (Self, Ordering) {
530 self.acsc_prec_round_ref(self.significant_bits(), rm)
531 }
532
533 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], in place, rounding the
534 /// result to the specified precision and with the specified rounding mode. An [`Ordering`] is
535 /// returned, indicating whether the rounded arccosecant is less than, equal to, or greater than
536 /// the exact arccosecant. Although `NaN`s are not comparable to any [`Float`], whenever this
537 /// function assigns a `NaN` it also returns `Equal`.
538 ///
539 /// See [`Float::acsc_prec_round`] for the error bounds, the special cases, and the complexity;
540 /// this function behaves the same way.
541 ///
542 /// # Panics
543 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
544 /// with the given precision.
545 ///
546 /// # Examples
547 /// ```
548 /// use malachite_base::num::basic::traits::Two;
549 /// use malachite_base::rounding_modes::RoundingMode::*;
550 /// use malachite_float::Float;
551 /// use std::cmp::Ordering::*;
552 ///
553 /// let mut x = Float::TWO;
554 /// let o = x.acsc_prec_round_assign(10, Floor);
555 /// assert_eq!(x.to_string(), "0.52344");
556 /// assert_eq!(o, Less);
557 /// ```
558 #[inline]
559 pub fn acsc_prec_round_assign(&mut self, prec: u64, rm: RoundingMode) -> Ordering {
560 let (s, o) = self.acsc_prec_round_ref(prec, rm);
561 *self = s;
562 o
563 }
564
565 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], in place, rounding the
566 /// result to the nearest value of the specified precision. An [`Ordering`] is returned,
567 /// indicating whether the rounded arccosecant is less than, equal to, or greater than the exact
568 /// arccosecant. Although `NaN`s are not comparable to any [`Float`], whenever this function
569 /// assigns a `NaN` it also returns `Equal`.
570 ///
571 /// See [`Float::acsc_prec`] and [`Float::acsc_prec_round`]; this function behaves the same way.
572 ///
573 /// # Panics
574 /// Panics if `prec` is zero.
575 ///
576 /// # Examples
577 /// ```
578 /// use malachite_base::num::basic::traits::Two;
579 /// use malachite_float::Float;
580 /// use std::cmp::Ordering::*;
581 ///
582 /// let mut x = Float::TWO;
583 /// let o = x.acsc_prec_assign(10);
584 /// assert_eq!(x.to_string(), "0.52344");
585 /// assert_eq!(o, Less);
586 /// ```
587 #[inline]
588 pub fn acsc_prec_assign(&mut self, prec: u64) -> Ordering {
589 self.acsc_prec_round_assign(prec, Nearest)
590 }
591
592 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], in place, rounding the
593 /// result with the specified rounding mode. The precision of the output is the precision of the
594 /// input. An [`Ordering`] is returned, indicating whether the rounded arccosecant is less than,
595 /// equal to, or greater than the exact arccosecant. Although `NaN`s are not comparable to any
596 /// [`Float`], whenever this function assigns a `NaN` it also returns `Equal`.
597 ///
598 /// See [`Float::acsc_round`] and [`Float::acsc_prec_round`]; this function behaves the same
599 /// way.
600 ///
601 /// # Panics
602 /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
603 /// the input.
604 ///
605 /// # Examples
606 /// ```
607 /// use malachite_base::rounding_modes::RoundingMode::*;
608 /// use malachite_float::Float;
609 /// use std::cmp::Ordering::*;
610 ///
611 /// let mut x = Float::from_unsigned_prec(2u32, 100).0;
612 /// let o = x.acsc_round_assign(Floor);
613 /// assert_eq!(x.to_string(), "0.52359877559829887307710723054603");
614 /// assert_eq!(o, Less);
615 /// ```
616 #[inline]
617 pub fn acsc_round_assign(&mut self, rm: RoundingMode) -> Ordering {
618 self.acsc_prec_round_assign(self.significant_bits(), rm)
619 }
620
621 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Rational`], rounding the result to
622 /// the specified precision and with the specified rounding mode and returning the result as a
623 /// [`Float`]. The [`Rational`] is taken by value. An [`Ordering`] is also returned, indicating
624 /// whether the rounded arccosecant is less than, equal to, or greater than the exact
625 /// arccosecant.
626 ///
627 /// See [`RoundingMode`] for a description of the possible rounding modes.
628 ///
629 /// $$
630 /// f(x,p,m) = \operatorname{acsc}(x)+\varepsilon.
631 /// $$
632 /// - If $|x|<1$, $\varepsilon$ may be ignored or assumed to be 0.
633 /// - Otherwise, if $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2
634 /// |\operatorname{acsc}(x)|\rfloor-p+1}$.
635 /// - Otherwise, if $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2
636 /// |\operatorname{acsc}(x)|\rfloor-p}$.
637 ///
638 /// The output has precision `prec`.
639 ///
640 /// Special cases:
641 /// - $f(x,p,m)=\text{NaN}$ for $|x|<1$, including zero
642 /// - $f(1,p,m)=\pi/2$ and $f(-1,p,m)=-\pi/2$
643 ///
644 /// The inputs of magnitude below 1 are the only exact cases, $\pi/2$ never being representable
645 /// and the infinities that give a zero being out of a [`Rational`]'s reach.
646 ///
647 /// The arccosecant is odd, so $f(-x,p,m)=-f(x,p,-m)$, with $-m$ the reflection of $m$ that
648 /// swaps `Floor` and `Ceiling`.
649 ///
650 /// Underflow:
651 /// - If $0<|f(x,p,m)|<2^{-2^{30}}$, and $m$ is `Floor`, `Down`, or `Nearest` with the result at
652 /// most $2^{-2^{30}-1}$ in magnitude, a zero of the result's sign is returned instead.
653 /// - Otherwise, if $0<|f(x,p,m)|<2^{-2^{30}}$, $\pm2^{-2^{30}}$ is returned instead, with the
654 /// sign of the result.
655 ///
656 /// Overflow is not possible, since $|\operatorname{acsc}(x)| \leq \pi/2$. Underflow, which the
657 /// [`Float`] arccosecant cannot reach, is possible here: $\operatorname{acsc}(x)$ is about
658 /// $1/x$ for a large $|x|$, and a [`Rational`] has no exponent bound, so $|x|$ can be large
659 /// enough to put the result below the smallest positive [`Float`].
660 ///
661 /// If you know you'll be using `Nearest`, consider using [`Float::acsc_rational_prec`] instead.
662 ///
663 /// # Worst-case complexity
664 /// $T(n, m) = O(n (\log n)^3 \log\log n + m \log m \log\log m)$
665 ///
666 /// $M(n, m) = O(n \log n + m \log m)$
667 ///
668 /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, and $m$ is
669 /// `x.significant_bits()`: $x^2-1$ is formed exactly, and the arctangent of the reciprocal of
670 /// its square root is taken at a working precision of about $n$ bits, which costs the first
671 /// term; the second is the square. A large $x$ skips the square altogether, its arccosecant
672 /// being the arctangent of the reciprocal of $|x|$ to within the working precision.
673 ///
674 /// # Panics
675 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
676 /// with the given precision (which is the case unless $|x|<1$).
677 ///
678 /// # Examples
679 /// ```
680 /// use malachite_base::num::basic::traits::{NegativeOne, Two};
681 /// use malachite_base::rounding_modes::RoundingMode::*;
682 /// use malachite_float::Float;
683 /// use malachite_q::Rational;
684 /// use std::cmp::Ordering::*;
685 ///
686 /// let (c, o) = Float::acsc_rational_prec_round(Rational::TWO, 10, Floor);
687 /// assert_eq!(c.to_string(), "0.52344");
688 /// assert_eq!(o, Less);
689 ///
690 /// let (c, o) = Float::acsc_rational_prec_round(Rational::TWO, 10, Ceiling);
691 /// assert_eq!(c.to_string(), "0.52441");
692 /// assert_eq!(o, Greater);
693 ///
694 /// // an input of -1 gives -pi/2
695 /// let (c, o) = Float::acsc_rational_prec_round(Rational::NEGATIVE_ONE, 10, Nearest);
696 /// assert_eq!(c.to_string(), "-1.5703");
697 /// assert_eq!(o, Greater);
698 /// ```
699 #[inline]
700 #[allow(clippy::needless_pass_by_value)]
701 pub fn acsc_rational_prec_round(x: Rational, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
702 Self::acsc_rational_prec_round_ref(&x, prec, rm)
703 }
704
705 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Rational`], rounding the result to
706 /// the specified precision and with the specified rounding mode and returning the result as a
707 /// [`Float`]. The [`Rational`] is taken by reference. An [`Ordering`] is also returned,
708 /// indicating whether the rounded arccosecant is less than, equal to, or greater than the exact
709 /// arccosecant.
710 ///
711 /// See [`Float::acsc_rational_prec_round`] for the error bounds, the special cases, underflow,
712 /// and the complexity; this function behaves the same way.
713 ///
714 /// # Panics
715 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
716 /// with the given precision.
717 ///
718 /// # Examples
719 /// ```
720 /// use malachite_base::rounding_modes::RoundingMode::*;
721 /// use malachite_float::Float;
722 /// use malachite_q::Rational;
723 /// use std::cmp::Ordering::*;
724 ///
725 /// let (c, o) =
726 /// Float::acsc_rational_prec_round_ref(&Rational::from_unsigneds(5u8, 3), 10, Floor);
727 /// assert_eq!(c.to_string(), "0.64258");
728 /// assert_eq!(o, Less);
729 /// ```
730 pub fn acsc_rational_prec_round_ref(
731 x: &Rational,
732 prec: u64,
733 rm: RoundingMode,
734 ) -> (Self, Ordering) {
735 assert_ne!(prec, 0);
736 match x.partial_cmp_abs(&1u32).unwrap() {
737 // the arccosecant is NaN inside (-1, 1), zero included
738 Less => (Self::NAN, Equal),
739 // acsc(1) = pi/2 and acsc(-1) = -pi/2
740 Equal => {
741 assert_ne!(rm, Exact, "Inexact acsc_rational");
742 signed_half_pi(*x < 0u32, prec, rm)
743 }
744 Greater => acsc_rational_helper(x, prec, rm),
745 }
746 }
747
748 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Rational`], rounding the result to
749 /// the nearest value of the specified precision and returning the result as a [`Float`]. The
750 /// [`Rational`] is taken by value. An [`Ordering`] is also returned, indicating whether the
751 /// rounded arccosecant is less than, equal to, or greater than the exact arccosecant.
752 ///
753 /// If the arccosecant is equidistant from two [`Float`]s with the specified precision, the
754 /// [`Float`] with fewer 1s in its binary expansion is chosen.
755 ///
756 /// See [`Float::acsc_rational_prec_round`] for the error bounds, the special cases, underflow,
757 /// and the complexity; this function behaves the same way.
758 ///
759 /// If you want to use a rounding mode other than `Nearest`, consider using
760 /// [`Float::acsc_rational_prec_round`] instead.
761 ///
762 /// # Panics
763 /// Panics if `prec` is zero.
764 ///
765 /// # Examples
766 /// ```
767 /// use malachite_float::Float;
768 /// use malachite_q::Rational;
769 /// use std::cmp::Ordering::*;
770 ///
771 /// let (c, o) = Float::acsc_rational_prec(Rational::from_unsigneds(5u8, 3), 53);
772 /// assert_eq!(c.to_string(), "0.64350110879328437");
773 /// assert_eq!(o, Less);
774 /// ```
775 #[inline]
776 pub fn acsc_rational_prec(x: Rational, prec: u64) -> (Self, Ordering) {
777 Self::acsc_rational_prec_round(x, prec, Nearest)
778 }
779
780 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Rational`], rounding the result to
781 /// the nearest value of the specified precision and returning the result as a [`Float`]. The
782 /// [`Rational`] is taken by reference. An [`Ordering`] is also returned, indicating whether the
783 /// rounded arccosecant is less than, equal to, or greater than the exact arccosecant.
784 ///
785 /// See [`Float::acsc_rational_prec`] and [`Float::acsc_rational_prec_round`]; this function
786 /// behaves the same way.
787 ///
788 /// # Panics
789 /// Panics if `prec` is zero.
790 ///
791 /// # Examples
792 /// ```
793 /// use malachite_float::Float;
794 /// use malachite_q::Rational;
795 /// use std::cmp::Ordering::*;
796 ///
797 /// let (c, o) = Float::acsc_rational_prec_ref(&Rational::from_unsigneds(5u8, 3), 53);
798 /// assert_eq!(c.to_string(), "0.64350110879328437");
799 /// assert_eq!(o, Less);
800 /// ```
801 #[inline]
802 pub fn acsc_rational_prec_ref(x: &Rational, prec: u64) -> (Self, Ordering) {
803 Self::acsc_rational_prec_round_ref(x, prec, Nearest)
804 }
805
806 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
807 /// of a turn, rounding the result to the specified precision and with the specified rounding
808 /// mode. The [`Float`] is taken by value. An [`Ordering`] is also returned, indicating whether
809 /// the rounded arccosecant is less than, equal to, or greater than the exact arccosecant.
810 /// Although `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN`
811 /// it also returns `Equal`.
812 ///
813 /// See [`RoundingMode`] for a description of the possible rounding modes.
814 ///
815 /// $$
816 /// f(x,u,p,m) = \operatorname{acsc}(x)u/(2\pi)+\varepsilon.
817 /// $$
818 /// - If $x$ is NaN or infinite, if $|x|<1$, if $u = 0$, if $|x|$ is 1, or if $|x|$ is 2 and $u$
819 /// is a multiple of 3, $\varepsilon$ may be ignored or assumed to be 0.
820 /// - Otherwise, if $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2
821 /// |\operatorname{acsc}(x)u/(2\pi)|\rfloor-p+1}$.
822 /// - Otherwise, if $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2
823 /// |\operatorname{acsc}(x)u/(2\pi)|\rfloor-p}$.
824 ///
825 /// If the output has a precision, it is `prec`.
826 ///
827 /// Special cases:
828 /// - $f(\text{NaN},u,p,m)=\text{NaN}$
829 /// - $f(x,u,p,m)=\text{NaN}$ for $|x|<1$, including $\pm0.0$ and when $u=0$
830 /// - $f(\pm\infty,u,p,m)=\pm0.0$
831 /// - $f(x,0,p,m)=\pm0.0$ for $|x|\geq1$, with the sign of $x$
832 /// - $f(\pm1,u,p,m)=\pm u/4$, a quarter turn
833 /// - $f(\pm2,u,p,m)=\pm u/12$, a twelfth of a turn, when $u$ is a multiple of 3
834 ///
835 /// Those are the only exact cases -- the arccosecant's exact values are the arcsine's, seen
836 /// through the reciprocal -- and the turn fractions are exact only when $p$ is large enough to
837 /// hold them.
838 ///
839 /// The arccosecant is odd, so $f(-x,u,p,m)=-f(x,u,p,-m)$, with $-m$ the reflection of $m$ that
840 /// swaps `Floor` and `Ceiling`; a zero period gives a zero with the sign of $x$ for the same
841 /// reason.
842 ///
843 /// Underflow:
844 /// - If $0<|f(x,u,p,m)|<2^{-2^{30}}$, and $m$ is `Floor`, `Down`, or `Nearest` with the result
845 /// at most $2^{-2^{30}-1}$ in magnitude, a zero of the result's sign is returned instead.
846 /// - Otherwise, if $0<|f(x,u,p,m)|<2^{-2^{30}}$, $\pm2^{-2^{30}}$ is returned instead, with the
847 /// sign of the result.
848 ///
849 /// Overflow is not possible, since $|f(x,u,p,m)| \leq u/4 < 2^{62}$. Underflow, which the
850 /// arccosecant alone cannot reach, is possible here: $|\operatorname{acsc}(x)|$ is about
851 /// $1/|x|$, which for the largest [`Float`]s is only twice the smallest positive one, so a
852 /// small $u$ carries the quotient below it.
853 ///
854 /// If you know you'll be using `Nearest`, consider using [`Float::acsc_with_period_prec`]
855 /// instead. If you know that your target precision is the precision of the input, consider
856 /// using [`Float::acsc_with_period_round`] instead.
857 ///
858 /// # Worst-case complexity
859 /// $T(n, m) = O(n (\log n)^3 \log\log n + m \log m \log\log m)$
860 ///
861 /// $M(n, m) = O(n \log n + m \log m)$
862 ///
863 /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, and $m$ is
864 /// `self.significant_bits()`: the arccosecant is taken at a working precision of about $n$ bits
865 /// and scaled by $u/(2\pi)$, which needs $\pi$ to that many bits, and both cost the first term;
866 /// the second is the exact square inside the arccosecant. A large $x$ skips the square, its
867 /// arccosecant being the reciprocal of $|x|$ to within the working precision.
868 ///
869 /// # Panics
870 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
871 /// with the given precision.
872 ///
873 /// # Examples
874 /// ```
875 /// use malachite_base::num::basic::traits::{NegativeOne, Two};
876 /// use malachite_base::rounding_modes::RoundingMode::*;
877 /// use malachite_float::Float;
878 /// use std::cmp::Ordering::*;
879 ///
880 /// // an input of 2 is a twelfth of a turn, and one of -1 minus a quarter
881 /// let (c, o) = Float::TWO.acsc_with_period_prec_round(360, 10, Exact);
882 /// assert_eq!(c.to_string(), "30.000");
883 /// assert_eq!(o, Equal);
884 ///
885 /// let (c, o) = Float::NEGATIVE_ONE.acsc_with_period_prec_round(360, 10, Exact);
886 /// assert_eq!(c.to_string(), "-90.000");
887 /// assert_eq!(o, Equal);
888 ///
889 /// let (c, o) = Float::from(2.5).acsc_with_period_prec_round(360, 10, Floor);
890 /// assert_eq!(c.to_string(), "23.562");
891 /// assert_eq!(o, Less);
892 /// ```
893 #[inline]
894 pub fn acsc_with_period_prec_round(
895 self,
896 u: u64,
897 prec: u64,
898 rm: RoundingMode,
899 ) -> (Self, Ordering) {
900 self.acsc_with_period_prec_round_ref(u, prec, rm)
901 }
902
903 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
904 /// of a turn, rounding the result to the specified precision and with the specified rounding
905 /// mode. The [`Float`] is taken by reference. An [`Ordering`] is also returned, indicating
906 /// whether the rounded arccosecant is less than, equal to, or greater than the exact
907 /// arccosecant. Although `NaN`s are not comparable to any [`Float`], whenever this function
908 /// returns a `NaN` it also returns `Equal`.
909 ///
910 /// See [`Float::acsc_with_period_prec_round`] for the error bounds, the special and closed-form
911 /// cases, underflow, and the complexity; this function behaves the same way.
912 ///
913 /// # Panics
914 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
915 /// with the given precision.
916 ///
917 /// # Examples
918 /// ```
919 /// use malachite_base::rounding_modes::RoundingMode::*;
920 /// use malachite_float::Float;
921 /// use std::cmp::Ordering::*;
922 ///
923 /// let (c, o) = (&Float::from(2.5)).acsc_with_period_prec_round_ref(360, 10, Ceiling);
924 /// assert_eq!(c.to_string(), "23.594");
925 /// assert_eq!(o, Greater);
926 /// ```
927 pub fn acsc_with_period_prec_round_ref(
928 &self,
929 u: u64,
930 prec: u64,
931 rm: RoundingMode,
932 ) -> (Self, Ordering) {
933 assert_ne!(prec, 0);
934 match &self.0 {
935 // the arccosecant is NaN inside (-1, 1), and both zeros are inside it; this holds for a
936 // zero period too, since NaN times 0 is NaN
937 NaN | Zero { .. } => (Self::NAN, Equal),
938 // acsc(±infinity) = ±0, so acscu(±infinity, u) = ±0 for every u, zero included
939 Infinity { sign } => (
940 if *sign {
941 Self::ZERO
942 } else {
943 Self::NEGATIVE_ZERO
944 },
945 Equal,
946 ),
947 Finite { sign, .. } => {
948 if self.lt_abs(&1u32) {
949 (Self::NAN, Equal)
950 } else if u == 0 {
951 // acscu(x, 0) = 0 with the sign of x, which agrees with the infinite case and
952 // keeps the function odd
953 (
954 if *sign {
955 Self::ZERO
956 } else {
957 Self::NEGATIVE_ZERO
958 },
959 Equal,
960 )
961 } else {
962 acsc_with_period_prec_round_normal_ref(self, u, prec, rm)
963 }
964 }
965 }
966 }
967
968 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
969 /// of a turn, rounding the result to the nearest value of the specified precision. The
970 /// [`Float`] is taken by value. An [`Ordering`] is also returned, indicating whether the
971 /// rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although
972 /// `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN` it also
973 /// returns `Equal`.
974 ///
975 /// If the arccosecant is equidistant from two [`Float`]s with the specified precision, the
976 /// [`Float`] with fewer 1s in its binary expansion is chosen.
977 ///
978 /// See [`Float::acsc_with_period_prec_round`] for the error bounds, the special and closed-form
979 /// cases, underflow, and the complexity; this function behaves the same way.
980 ///
981 /// If you want to use a rounding mode other than `Nearest`, consider using
982 /// [`Float::acsc_with_period_prec_round`] instead.
983 ///
984 /// # Panics
985 /// Panics if `prec` is zero.
986 ///
987 /// # Examples
988 /// ```
989 /// use malachite_float::Float;
990 /// use std::cmp::Ordering::*;
991 ///
992 /// let (c, o) = Float::from(2.5).acsc_with_period_prec(360, 10);
993 /// assert_eq!(c.to_string(), "23.594");
994 /// assert_eq!(o, Greater);
995 ///
996 /// let (c, o) = Float::from(2.5).acsc_with_period_prec(360, 53);
997 /// assert_eq!(c.to_string(), "23.578178478201831");
998 /// assert_eq!(o, Greater);
999 /// ```
1000 #[inline]
1001 pub fn acsc_with_period_prec(self, u: u64, prec: u64) -> (Self, Ordering) {
1002 self.acsc_with_period_prec_round(u, prec, Nearest)
1003 }
1004
1005 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
1006 /// of a turn, rounding the result to the nearest value of the specified precision. The
1007 /// [`Float`] is taken by reference. An [`Ordering`] is also returned, indicating whether the
1008 /// rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although
1009 /// `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN` it also
1010 /// returns `Equal`.
1011 ///
1012 /// See [`Float::acsc_with_period_prec`] and [`Float::acsc_with_period_prec_round`]; this
1013 /// function behaves the same way.
1014 ///
1015 /// # Panics
1016 /// Panics if `prec` is zero.
1017 ///
1018 /// # Examples
1019 /// ```
1020 /// use malachite_float::Float;
1021 /// use std::cmp::Ordering::*;
1022 ///
1023 /// let (c, o) = (&Float::from(2.5)).acsc_with_period_prec_ref(360, 53);
1024 /// assert_eq!(c.to_string(), "23.578178478201831");
1025 /// assert_eq!(o, Greater);
1026 /// ```
1027 #[inline]
1028 pub fn acsc_with_period_prec_ref(&self, u: u64, prec: u64) -> (Self, Ordering) {
1029 self.acsc_with_period_prec_round_ref(u, prec, Nearest)
1030 }
1031
1032 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
1033 /// of a turn, rounding the result with the specified rounding mode. The precision of the output
1034 /// is the precision of the input. The [`Float`] is taken by value. An [`Ordering`] is also
1035 /// returned, indicating whether the rounded arccosecant is less than, equal to, or greater than
1036 /// the exact arccosecant. Although `NaN`s are not comparable to any [`Float`], whenever this
1037 /// function returns a `NaN` it also returns `Equal`.
1038 ///
1039 /// See [`Float::acsc_with_period_prec_round`] for the error bounds, the special and closed-form
1040 /// cases, underflow, and the complexity; this function behaves the same way, with `prec` the
1041 /// precision of the input.
1042 ///
1043 /// # Panics
1044 /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
1045 /// the input.
1046 ///
1047 /// # Examples
1048 /// ```
1049 /// use malachite_base::rounding_modes::RoundingMode::*;
1050 /// use malachite_float::Float;
1051 /// use std::cmp::Ordering::*;
1052 ///
1053 /// let x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
1054 /// let (c, o) = x.acsc_with_period_round(360, Floor);
1055 /// assert_eq!(c.to_string(), "23.578178478201831104022499419824");
1056 /// assert_eq!(o, Less);
1057 /// ```
1058 #[inline]
1059 pub fn acsc_with_period_round(self, u: u64, rm: RoundingMode) -> (Self, Ordering) {
1060 let prec = self.significant_bits();
1061 self.acsc_with_period_prec_round(u, prec, rm)
1062 }
1063
1064 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
1065 /// of a turn, rounding the result with the specified rounding mode. The precision of the output
1066 /// is the precision of the input. The [`Float`] is taken by reference. An [`Ordering`] is also
1067 /// returned, indicating whether the rounded arccosecant is less than, equal to, or greater than
1068 /// the exact arccosecant. Although `NaN`s are not comparable to any [`Float`], whenever this
1069 /// function returns a `NaN` it also returns `Equal`.
1070 ///
1071 /// See [`Float::acsc_with_period_round`] and [`Float::acsc_with_period_prec_round`]; this
1072 /// function behaves the same way.
1073 ///
1074 /// # Panics
1075 /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
1076 /// the input.
1077 ///
1078 /// # Examples
1079 /// ```
1080 /// use malachite_base::rounding_modes::RoundingMode::*;
1081 /// use malachite_float::Float;
1082 /// use std::cmp::Ordering::*;
1083 ///
1084 /// let x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
1085 /// let (c, o) = (&x).acsc_with_period_round_ref(360, Ceiling);
1086 /// assert_eq!(c.to_string(), "23.578178478201831104022499419849");
1087 /// assert_eq!(o, Greater);
1088 /// ```
1089 #[inline]
1090 pub fn acsc_with_period_round_ref(&self, u: u64, rm: RoundingMode) -> (Self, Ordering) {
1091 self.acsc_with_period_prec_round_ref(u, self.significant_bits(), rm)
1092 }
1093
1094 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
1095 /// of a turn, rounding the result to the precision of the input and to the nearest [`Float`].
1096 /// The [`Float`] is taken by value.
1097 ///
1098 /// If the arccosecant is equidistant from two [`Float`]s with the precision of the input, the
1099 /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1100 /// description of the `Nearest` rounding mode.
1101 ///
1102 /// See [`Float::acsc_with_period_prec_round`] for the error bounds, the special and closed-form
1103 /// cases, underflow, and the complexity; this function behaves the same way, with `prec` the
1104 /// precision of the input and `Nearest` rounding.
1105 ///
1106 /// If you want to use a rounding mode other than `Nearest`, consider using
1107 /// [`Float::acsc_with_period_round`] instead. If you want to specify an output precision,
1108 /// consider using [`Float::acsc_with_period_prec`]. If you want both of these things, consider
1109 /// using [`Float::acsc_with_period_prec_round`].
1110 ///
1111 /// # Examples
1112 /// ```
1113 /// use malachite_float::Float;
1114 ///
1115 /// let x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
1116 /// assert_eq!(
1117 /// x.acsc_with_period(360).to_string(),
1118 /// "23.578178478201831104022499419824"
1119 /// );
1120 /// ```
1121 #[inline]
1122 pub fn acsc_with_period(self, u: u64) -> Self {
1123 let prec = self.significant_bits();
1124 self.acsc_with_period_prec(u, prec).0
1125 }
1126
1127 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
1128 /// of a turn, rounding the result to the precision of the input and to the nearest [`Float`].
1129 /// The [`Float`] is taken by reference.
1130 ///
1131 /// See [`Float::acsc_with_period`] and [`Float::acsc_with_period_prec_round`]; this function
1132 /// behaves the same way.
1133 ///
1134 /// # Examples
1135 /// ```
1136 /// use malachite_float::Float;
1137 ///
1138 /// let x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
1139 /// assert_eq!(
1140 /// (&x).acsc_with_period_ref(360).to_string(),
1141 /// "23.578178478201831104022499419824"
1142 /// );
1143 /// ```
1144 #[inline]
1145 pub fn acsc_with_period_ref(&self, u: u64) -> Self {
1146 self.acsc_with_period_prec_ref(u, self.significant_bits()).0
1147 }
1148
1149 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
1150 /// of a turn, in place, rounding the result to the specified precision and with the specified
1151 /// rounding mode. An [`Ordering`] is returned, indicating whether the rounded arccosecant is
1152 /// less than, equal to, or greater than the exact arccosecant. Although `NaN`s are not
1153 /// comparable to any [`Float`], whenever this function assigns a `NaN` it also returns `Equal`.
1154 ///
1155 /// See [`Float::acsc_with_period_prec_round`] for the error bounds, the special and closed-form
1156 /// cases, underflow, and the complexity; this function behaves the same way.
1157 ///
1158 /// # Panics
1159 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1160 /// with the given precision.
1161 ///
1162 /// # Examples
1163 /// ```
1164 /// use malachite_base::rounding_modes::RoundingMode::*;
1165 /// use malachite_float::Float;
1166 /// use std::cmp::Ordering::*;
1167 ///
1168 /// let mut x = Float::from(2.5);
1169 /// let o = x.acsc_with_period_prec_round_assign(360, 10, Floor);
1170 /// assert_eq!(x.to_string(), "23.562");
1171 /// assert_eq!(o, Less);
1172 /// ```
1173 #[inline]
1174 pub fn acsc_with_period_prec_round_assign(
1175 &mut self,
1176 u: u64,
1177 prec: u64,
1178 rm: RoundingMode,
1179 ) -> Ordering {
1180 let (s, o) = self.acsc_with_period_prec_round_ref(u, prec, rm);
1181 *self = s;
1182 o
1183 }
1184
1185 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
1186 /// of a turn, in place, rounding the result to the nearest value of the specified precision. An
1187 /// [`Ordering`] is returned, indicating whether the rounded arccosecant is less than, equal to,
1188 /// or greater than the exact arccosecant. Although `NaN`s are not comparable to any [`Float`],
1189 /// whenever this function assigns a `NaN` it also returns `Equal`.
1190 ///
1191 /// See [`Float::acsc_with_period_prec`] and [`Float::acsc_with_period_prec_round`]; this
1192 /// function behaves the same way.
1193 ///
1194 /// # Panics
1195 /// Panics if `prec` is zero.
1196 ///
1197 /// # Examples
1198 /// ```
1199 /// use malachite_float::Float;
1200 /// use std::cmp::Ordering::*;
1201 ///
1202 /// let mut x = Float::from(2.5);
1203 /// let o = x.acsc_with_period_prec_assign(360, 10);
1204 /// assert_eq!(x.to_string(), "23.594");
1205 /// assert_eq!(o, Greater);
1206 /// ```
1207 #[inline]
1208 pub fn acsc_with_period_prec_assign(&mut self, u: u64, prec: u64) -> Ordering {
1209 self.acsc_with_period_prec_round_assign(u, prec, Nearest)
1210 }
1211
1212 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
1213 /// of a turn, in place, rounding the result with the specified rounding mode. The precision of
1214 /// the output is the precision of the input. An [`Ordering`] is returned, indicating whether
1215 /// the rounded arccosecant is less than, equal to, or greater than the exact arccosecant.
1216 /// Although `NaN`s are not comparable to any [`Float`], whenever this function assigns a `NaN`
1217 /// it also returns `Equal`.
1218 ///
1219 /// See [`Float::acsc_with_period_round`] and [`Float::acsc_with_period_prec_round`]; this
1220 /// function behaves the same way.
1221 ///
1222 /// # Panics
1223 /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
1224 /// the input.
1225 ///
1226 /// # Examples
1227 /// ```
1228 /// use malachite_base::rounding_modes::RoundingMode::*;
1229 /// use malachite_float::Float;
1230 /// use std::cmp::Ordering::*;
1231 ///
1232 /// let mut x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
1233 /// let o = x.acsc_with_period_round_assign(360, Floor);
1234 /// assert_eq!(x.to_string(), "23.578178478201831104022499419824");
1235 /// assert_eq!(o, Less);
1236 /// ```
1237 #[inline]
1238 pub fn acsc_with_period_round_assign(&mut self, u: u64, rm: RoundingMode) -> Ordering {
1239 self.acsc_with_period_prec_round_assign(u, self.significant_bits(), rm)
1240 }
1241
1242 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Float`] measured in $u$ths
1243 /// of a turn, in place, rounding the result to the precision of the input and to the nearest
1244 /// [`Float`].
1245 ///
1246 /// If the arccosecant is equidistant from two [`Float`]s with the precision of the input, the
1247 /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1248 /// description of the `Nearest` rounding mode.
1249 ///
1250 /// See [`Float::acsc_with_period`] and [`Float::acsc_with_period_prec_round`]; this function
1251 /// behaves the same way.
1252 ///
1253 /// # Examples
1254 /// ```
1255 /// use malachite_float::Float;
1256 ///
1257 /// let mut x = Float::from_unsigned_prec(5u32, 100).0 >> 1u32;
1258 /// x.acsc_with_period_assign(360);
1259 /// assert_eq!(x.to_string(), "23.578178478201831104022499419824");
1260 /// ```
1261 #[inline]
1262 pub fn acsc_with_period_assign(&mut self, u: u64) {
1263 let prec = self.significant_bits();
1264 self.acsc_with_period_prec_assign(u, prec);
1265 }
1266
1267 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Rational`] measured in
1268 /// $u$ths of a turn, rounding the result to the specified precision and with the specified
1269 /// rounding mode and returning the result as a [`Float`]. The [`Rational`] is taken by value.
1270 /// An [`Ordering`] is also returned, indicating whether the rounded arccosecant is less than,
1271 /// equal to, or greater than the exact arccosecant.
1272 ///
1273 /// See [`RoundingMode`] for a description of the possible rounding modes.
1274 ///
1275 /// $$
1276 /// f(x,u,p,m) = \operatorname{acsc}(x)u/(2\pi)+\varepsilon.
1277 /// $$
1278 /// - If $|x|<1$, if $u = 0$, if $|x|$ is 1, or if $|x|$ is 2 and $u$ is a multiple of 3,
1279 /// $\varepsilon$ may be ignored or assumed to be 0.
1280 /// - Otherwise, if $m$ is not `Nearest`, then $|\varepsilon| < 2^{\lfloor\log_2
1281 /// |\operatorname{acsc}(x)u/(2\pi)|\rfloor-p+1}$.
1282 /// - Otherwise, if $m$ is `Nearest`, then $|\varepsilon| \leq 2^{\lfloor\log_2
1283 /// |\operatorname{acsc}(x)u/(2\pi)|\rfloor-p}$.
1284 ///
1285 /// The output has precision `prec`.
1286 ///
1287 /// Special cases:
1288 /// - $f(x,u,p,m)=\text{NaN}$ for $|x|<1$, including zero and when $u=0$
1289 /// - $f(x,0,p,m)=\pm0.0$ for $|x|\geq1$, with the sign of $x$
1290 /// - $f(\pm1,u,p,m)=\pm u/4$, a quarter turn
1291 /// - $f(\pm2,u,p,m)=\pm u/12$, a twelfth of a turn, when $u$ is a multiple of 3
1292 ///
1293 /// Those are the only exact cases, and the turn fractions are exact only when $p$ is large
1294 /// enough to hold them.
1295 ///
1296 /// The arccosecant is odd, so $f(-x,u,p,m)=-f(x,u,p,-m)$, with $-m$ the reflection of $m$ that
1297 /// swaps `Floor` and `Ceiling`.
1298 ///
1299 /// Underflow:
1300 /// - If $0<|f(x,u,p,m)|<2^{-2^{30}}$, and $m$ is `Floor`, `Down`, or `Nearest` with the result
1301 /// at most $2^{-2^{30}-1}$ in magnitude, a zero of the result's sign is returned instead.
1302 /// - Otherwise, if $0<|f(x,u,p,m)|<2^{-2^{30}}$, $\pm2^{-2^{30}}$ is returned instead, with the
1303 /// sign of the result.
1304 ///
1305 /// Overflow is not possible, since $|f(x,u,p,m)| \leq u/4 < 2^{62}$. Underflow needs a small
1306 /// $u$ together with a large $|x|$; a [`Rational`] has no exponent bound, so $|x|$ can be large
1307 /// enough for that at any $u$.
1308 ///
1309 /// If you know you'll be using `Nearest`, consider using
1310 /// [`Float::acsc_with_period_rational_prec`] instead.
1311 ///
1312 /// # Worst-case complexity
1313 /// $T(n, m) = O(n (\log n)^3 \log\log n + m \log m \log\log m)$
1314 ///
1315 /// $M(n, m) = O(n \log n + m \log m)$
1316 ///
1317 /// where $T$ is time, $M$ is additional memory, $n$ is `prec`, and $m$ is
1318 /// `x.significant_bits()`: $x^2-1$ is formed exactly, and the arctangent of the reciprocal of
1319 /// its square root is taken at a working precision of about $n$ bits and scaled by $u/(2\pi)$,
1320 /// which needs $\pi$ to that many bits; those cost the first term, and the second is the
1321 /// square. A large $x$ skips the square, its arccosecant being the reciprocal of $|x|$ to
1322 /// within the working precision.
1323 ///
1324 /// # Panics
1325 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1326 /// with the given precision.
1327 ///
1328 /// # Examples
1329 /// ```
1330 /// use malachite_base::num::basic::traits::{NegativeOne, Two};
1331 /// use malachite_base::rounding_modes::RoundingMode::*;
1332 /// use malachite_float::Float;
1333 /// use malachite_q::Rational;
1334 /// use std::cmp::Ordering::*;
1335 ///
1336 /// // an input of 2 is a twelfth of a turn, and one of -1 minus a quarter
1337 /// let (c, o) = Float::acsc_with_period_rational_prec_round(Rational::TWO, 360, 10, Exact);
1338 /// assert_eq!(c.to_string(), "30.000");
1339 /// assert_eq!(o, Equal);
1340 ///
1341 /// let (c, o) =
1342 /// Float::acsc_with_period_rational_prec_round(Rational::NEGATIVE_ONE, 360, 10, Exact);
1343 /// assert_eq!(c.to_string(), "-90.000");
1344 /// assert_eq!(o, Equal);
1345 ///
1346 /// let (c, o) = Float::acsc_with_period_rational_prec_round(
1347 /// Rational::from_unsigneds(5u8, 3),
1348 /// 360,
1349 /// 10,
1350 /// Floor,
1351 /// );
1352 /// assert_eq!(c.to_string(), "36.812");
1353 /// assert_eq!(o, Less);
1354 /// ```
1355 #[inline]
1356 #[allow(clippy::needless_pass_by_value)]
1357 pub fn acsc_with_period_rational_prec_round(
1358 x: Rational,
1359 u: u64,
1360 prec: u64,
1361 rm: RoundingMode,
1362 ) -> (Self, Ordering) {
1363 Self::acsc_with_period_rational_prec_round_ref(&x, u, prec, rm)
1364 }
1365
1366 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Rational`] measured in
1367 /// $u$ths of a turn, rounding the result to the specified precision and with the specified
1368 /// rounding mode and returning the result as a [`Float`]. The [`Rational`] is taken by
1369 /// reference. An [`Ordering`] is also returned, indicating whether the rounded arccosecant is
1370 /// less than, equal to, or greater than the exact arccosecant.
1371 ///
1372 /// See [`Float::acsc_with_period_rational_prec_round`] for the error bounds, the special and
1373 /// closed-form cases, underflow, and the complexity; this function behaves the same way.
1374 ///
1375 /// # Panics
1376 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1377 /// with the given precision.
1378 ///
1379 /// # Examples
1380 /// ```
1381 /// use malachite_base::rounding_modes::RoundingMode::*;
1382 /// use malachite_float::Float;
1383 /// use malachite_q::Rational;
1384 /// use std::cmp::Ordering::*;
1385 ///
1386 /// let (c, o) = Float::acsc_with_period_rational_prec_round_ref(
1387 /// &Rational::from_unsigneds(5u8, 3),
1388 /// 360,
1389 /// 10,
1390 /// Ceiling,
1391 /// );
1392 /// assert_eq!(c.to_string(), "36.875");
1393 /// assert_eq!(o, Greater);
1394 /// ```
1395 pub fn acsc_with_period_rational_prec_round_ref(
1396 x: &Rational,
1397 u: u64,
1398 prec: u64,
1399 rm: RoundingMode,
1400 ) -> (Self, Ordering) {
1401 assert_ne!(prec, 0);
1402 if x.lt_abs(&1u32) {
1403 // the arccosecant is NaN inside (-1, 1), zero included; this holds for a zero period
1404 // too, since NaN times 0 is NaN
1405 return (Self::NAN, Equal);
1406 }
1407 if u == 0 {
1408 // acscu(x, 0) = 0 with the sign of x, which keeps the function odd
1409 return (
1410 if *x > 0u32 {
1411 Self::ZERO
1412 } else {
1413 Self::NEGATIVE_ZERO
1414 },
1415 Equal,
1416 );
1417 }
1418 acsc_with_period_rational_helper(x, u, prec, rm)
1419 }
1420
1421 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Rational`] measured in
1422 /// $u$ths of a turn, rounding the result to the nearest value of the specified precision and
1423 /// returning the result as a [`Float`]. The [`Rational`] is taken by value. An [`Ordering`] is
1424 /// also returned, indicating whether the rounded arccosecant is less than, equal to, or greater
1425 /// than the exact arccosecant.
1426 ///
1427 /// If the arccosecant is equidistant from two [`Float`]s with the specified precision, the
1428 /// [`Float`] with fewer 1s in its binary expansion is chosen.
1429 ///
1430 /// See [`Float::acsc_with_period_rational_prec_round`] for the error bounds, the special and
1431 /// closed-form cases, underflow, and the complexity; this function behaves the same way.
1432 ///
1433 /// If you want to use a rounding mode other than `Nearest`, consider using
1434 /// [`Float::acsc_with_period_rational_prec_round`] instead.
1435 ///
1436 /// # Panics
1437 /// Panics if `prec` is zero.
1438 ///
1439 /// # Examples
1440 /// ```
1441 /// use malachite_float::Float;
1442 /// use malachite_q::Rational;
1443 /// use std::cmp::Ordering::*;
1444 ///
1445 /// let (c, o) =
1446 /// Float::acsc_with_period_rational_prec(Rational::from_unsigneds(5u8, 3), 360, 10);
1447 /// assert_eq!(c.to_string(), "36.875");
1448 /// assert_eq!(o, Greater);
1449 ///
1450 /// let (c, o) =
1451 /// Float::acsc_with_period_rational_prec(Rational::from_unsigneds(5u8, 3), 360, 53);
1452 /// assert_eq!(c.to_string(), "36.869897645844020");
1453 /// assert_eq!(o, Less);
1454 /// ```
1455 #[inline]
1456 pub fn acsc_with_period_rational_prec(x: Rational, u: u64, prec: u64) -> (Self, Ordering) {
1457 Self::acsc_with_period_rational_prec_round(x, u, prec, Nearest)
1458 }
1459
1460 /// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Rational`] measured in
1461 /// $u$ths of a turn, rounding the result to the nearest value of the specified precision and
1462 /// returning the result as a [`Float`]. The [`Rational`] is taken by reference. An [`Ordering`]
1463 /// is also returned, indicating whether the rounded arccosecant is less than, equal to, or
1464 /// greater than the exact arccosecant.
1465 ///
1466 /// See [`Float::acsc_with_period_rational_prec`] and
1467 /// [`Float::acsc_with_period_rational_prec_round`]; this function behaves the same way.
1468 ///
1469 /// # Panics
1470 /// Panics if `prec` is zero.
1471 ///
1472 /// # Examples
1473 /// ```
1474 /// use malachite_float::Float;
1475 /// use malachite_q::Rational;
1476 /// use std::cmp::Ordering::*;
1477 ///
1478 /// let (c, o) =
1479 /// Float::acsc_with_period_rational_prec_ref(&Rational::from_unsigneds(5u8, 3), 360, 53);
1480 /// assert_eq!(c.to_string(), "36.869897645844020");
1481 /// assert_eq!(o, Less);
1482 /// ```
1483 #[inline]
1484 pub fn acsc_with_period_rational_prec_ref(x: &Rational, u: u64, prec: u64) -> (Self, Ordering) {
1485 Self::acsc_with_period_rational_prec_round_ref(x, u, prec, Nearest)
1486 }
1487 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1488 /// half-turns, rounding the result to the specified precision and with the specified rounding
1489 /// mode. The [`Float`] is taken by value. An [`Ordering`] is also returned, indicating whether
1490 /// the rounded arccosecant is less than, equal to, or greater than the exact arccosecant.
1491 /// Although `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN`
1492 /// it also returns `Equal`.
1493 ///
1494 /// This is `acsc_with_period` with a period of 2: see [`Float::acsc_with_period_prec_round`]
1495 /// for the error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either
1496 /// infinity gives a zero of its sign, and an input of $\pm1$ gives $\pm1/2$; both are exact at
1497 /// every precision, since a half needs only one bit, and they are the only exact cases. Unlike
1498 /// the other periods, $\pm2$ are not exact ones, a sixth of a half-turn not being
1499 /// representable. NaN and any $|x|<1$, including the zeros, give NaN. Overflow is not possible,
1500 /// since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
1501 ///
1502 /// # Panics
1503 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1504 /// with the given precision.
1505 ///
1506 /// # Examples
1507 /// ```
1508 /// use malachite_base::num::basic::traits::Infinity;
1509 /// use malachite_base::rounding_modes::RoundingMode::*;
1510 /// use malachite_float::Float;
1511 /// use std::cmp::Ordering::*;
1512 ///
1513 /// // an infinity gives a zero, the cosecant falling to nothing there
1514 /// let (c, o) = Float::INFINITY.acsc_pi_prec_round(10, Exact);
1515 /// assert_eq!(c.to_string(), "0.0");
1516 /// assert_eq!(o, Equal);
1517 ///
1518 /// let (c, o) = Float::from(2.5).acsc_pi_prec_round(10, Floor);
1519 /// assert_eq!(c.to_string(), "0.13086");
1520 /// assert_eq!(o, Less);
1521 /// ```
1522 #[inline]
1523 pub fn acsc_pi_prec_round(self, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
1524 self.acsc_with_period_prec_round(2, prec, rm)
1525 }
1526
1527 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1528 /// half-turns, rounding the result to the specified precision and with the specified rounding
1529 /// mode. The [`Float`] is taken by reference. An [`Ordering`] is also returned, indicating
1530 /// whether the rounded arccosecant is less than, equal to, or greater than the exact
1531 /// arccosecant. Although `NaN`s are not comparable to any [`Float`], whenever this function
1532 /// returns a `NaN` it also returns `Equal`.
1533 ///
1534 /// This is `acsc_with_period` with a period of 2: see
1535 /// [`Float::acsc_with_period_prec_round_ref`] for the error bounds, the special cases,
1536 /// underflow, and the complexity, with $u = 2$. Either infinity gives a zero of its sign, and
1537 /// an input of $\pm1$ gives $\pm1/2$; both are exact at every precision, and they are the only
1538 /// exact cases. NaN and any $|x|<1$, including the zeros, give NaN. Overflow is not possible,
1539 /// since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
1540 ///
1541 /// # Panics
1542 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1543 /// with the given precision.
1544 ///
1545 /// # Examples
1546 /// ```
1547 /// use malachite_base::rounding_modes::RoundingMode::*;
1548 /// use malachite_float::Float;
1549 /// use std::cmp::Ordering::*;
1550 ///
1551 /// let (c, o) = (&Float::from(2.5)).acsc_pi_prec_round_ref(10, Ceiling);
1552 /// assert_eq!(c.to_string(), "0.13110");
1553 /// assert_eq!(o, Greater);
1554 /// ```
1555 #[inline]
1556 pub fn acsc_pi_prec_round_ref(&self, prec: u64, rm: RoundingMode) -> (Self, Ordering) {
1557 self.acsc_with_period_prec_round_ref(2, prec, rm)
1558 }
1559
1560 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1561 /// half-turns, rounding the result to the nearest value of the specified precision. The
1562 /// [`Float`] is taken by value. An [`Ordering`] is also returned, indicating whether the
1563 /// rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although
1564 /// `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN` it also
1565 /// returns `Equal`.
1566 ///
1567 /// If the arccosecant is equidistant from two [`Float`]s with the specified precision, the
1568 /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1569 /// description of the `Nearest` rounding mode.
1570 ///
1571 /// This is `acsc_with_period` with a period of 2: see [`Float::acsc_with_period_prec`] for the
1572 /// error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either
1573 /// infinity gives a zero of its sign, and an input of $\pm1$ gives $\pm1/2$; both are exact at
1574 /// every precision, and they are the only exact cases. NaN and any $|x|<1$, including the
1575 /// zeros, give NaN. Overflow is not possible, since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
1576 ///
1577 /// If you want to use a rounding mode other than `Nearest`, consider using
1578 /// [`Float::acsc_pi_prec_round`] instead.
1579 ///
1580 /// # Panics
1581 /// Panics if `prec` is zero.
1582 ///
1583 /// # Examples
1584 /// ```
1585 /// use malachite_float::Float;
1586 /// use std::cmp::Ordering::*;
1587 ///
1588 /// let (c, o) = Float::from(2.5).acsc_pi_prec(10);
1589 /// assert_eq!(c.to_string(), "0.13110");
1590 /// assert_eq!(o, Greater);
1591 /// ```
1592 #[inline]
1593 pub fn acsc_pi_prec(self, prec: u64) -> (Self, Ordering) {
1594 self.acsc_with_period_prec(2, prec)
1595 }
1596
1597 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1598 /// half-turns, rounding the result to the nearest value of the specified precision. The
1599 /// [`Float`] is taken by reference. An [`Ordering`] is also returned, indicating whether the
1600 /// rounded arccosecant is less than, equal to, or greater than the exact arccosecant. Although
1601 /// `NaN`s are not comparable to any [`Float`], whenever this function returns a `NaN` it also
1602 /// returns `Equal`.
1603 ///
1604 /// See [`Float::acsc_pi_prec`] and [`Float::acsc_with_period_prec_round`]; this function
1605 /// behaves the same way.
1606 ///
1607 /// # Panics
1608 /// Panics if `prec` is zero.
1609 ///
1610 /// # Examples
1611 /// ```
1612 /// use malachite_float::Float;
1613 /// use std::cmp::Ordering::*;
1614 ///
1615 /// let (c, o) = (&Float::from(2.5)).acsc_pi_prec_ref(53);
1616 /// assert_eq!(c.to_string(), "0.13098988043445461");
1617 /// assert_eq!(o, Less);
1618 /// ```
1619 #[inline]
1620 pub fn acsc_pi_prec_ref(&self, prec: u64) -> (Self, Ordering) {
1621 self.acsc_with_period_prec_ref(2, prec)
1622 }
1623
1624 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1625 /// half-turns, rounding the result with the specified rounding mode. The precision of the
1626 /// output is the precision of the input. The [`Float`] is taken by value. An [`Ordering`] is
1627 /// also returned, indicating whether the rounded arccosecant is less than, equal to, or greater
1628 /// than the exact arccosecant. Although `NaN`s are not comparable to any [`Float`], whenever
1629 /// this function returns a `NaN` it also returns `Equal`.
1630 ///
1631 /// This is `acsc_with_period` with a period of 2: see [`Float::acsc_with_period_round`] for the
1632 /// error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either
1633 /// infinity gives a zero of its sign, and an input of $\pm1$ gives $\pm1/2$; both are exact at
1634 /// every precision, and they are the only exact cases. NaN and any $|x|<1$, including the
1635 /// zeros, give NaN. Overflow is not possible, since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
1636 ///
1637 /// # Panics
1638 /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
1639 /// the input.
1640 ///
1641 /// # Examples
1642 /// ```
1643 /// use malachite_base::rounding_modes::RoundingMode::*;
1644 /// use malachite_float::Float;
1645 /// use std::cmp::Ordering::*;
1646 ///
1647 /// let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
1648 /// let (c, o) = x.acsc_pi_round(Floor);
1649 /// assert_eq!(c.to_string(), "0.13086");
1650 /// assert_eq!(o, Less);
1651 /// ```
1652 #[inline]
1653 pub fn acsc_pi_round(self, rm: RoundingMode) -> (Self, Ordering) {
1654 self.acsc_with_period_round(2, rm)
1655 }
1656
1657 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1658 /// half-turns, rounding the result with the specified rounding mode. The precision of the
1659 /// output is the precision of the input. The [`Float`] is taken by reference. An [`Ordering`]
1660 /// is also returned, indicating whether the rounded arccosecant is less than, equal to, or
1661 /// greater than the exact arccosecant. Although `NaN`s are not comparable to any [`Float`],
1662 /// whenever this function returns a `NaN` it also returns `Equal`.
1663 ///
1664 /// This is `acsc_with_period` with a period of 2: see [`Float::acsc_with_period_round_ref`] for
1665 /// the error bounds, the special cases, underflow, and the complexity, with $u = 2$. Either
1666 /// infinity gives a zero of its sign, and an input of $\pm1$ gives $\pm1/2$; both are exact at
1667 /// every precision, and they are the only exact cases. NaN and any $|x|<1$, including the
1668 /// zeros, give NaN. Overflow is not possible, since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
1669 ///
1670 /// # Panics
1671 /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
1672 /// the input.
1673 ///
1674 /// # Examples
1675 /// ```
1676 /// use malachite_base::rounding_modes::RoundingMode::*;
1677 /// use malachite_float::Float;
1678 /// use std::cmp::Ordering::*;
1679 ///
1680 /// let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
1681 /// let (c, o) = (&x).acsc_pi_round_ref(Ceiling);
1682 /// assert_eq!(c.to_string(), "0.13110");
1683 /// assert_eq!(o, Greater);
1684 /// ```
1685 #[inline]
1686 pub fn acsc_pi_round_ref(&self, rm: RoundingMode) -> (Self, Ordering) {
1687 self.acsc_with_period_round_ref(2, rm)
1688 }
1689
1690 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1691 /// half-turns, rounding the result to the precision of the input and to the nearest [`Float`].
1692 /// The [`Float`] is taken by value.
1693 ///
1694 /// If the arccosecant is equidistant from two [`Float`]s with the precision of the input, the
1695 /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1696 /// description of the `Nearest` rounding mode.
1697 ///
1698 /// This is `acsc_with_period` with a period of 2: see [`Float::acsc_with_period`] for the error
1699 /// bounds, the special cases, underflow, and the complexity, with $u = 2$. Either infinity
1700 /// gives a zero of its sign, and an input of $\pm1$ gives $\pm1/2$; both are exact at every
1701 /// precision, and they are the only exact cases. NaN and any $|x|<1$, including the zeros, give
1702 /// NaN. Overflow is not possible, since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
1703 ///
1704 /// If you want to use a rounding mode other than `Nearest`, consider using
1705 /// [`Float::acsc_pi_round`] instead. If you want to specify an output precision, consider using
1706 /// [`Float::acsc_pi_prec`]. If you want both of these things, consider using
1707 /// [`Float::acsc_pi_prec_round`].
1708 ///
1709 /// # Examples
1710 /// ```
1711 /// use malachite_float::Float;
1712 ///
1713 /// let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
1714 /// assert_eq!(x.acsc_pi().to_string(), "0.13110");
1715 /// ```
1716 #[inline]
1717 pub fn acsc_pi(self) -> Self {
1718 self.acsc_with_period(2)
1719 }
1720
1721 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1722 /// half-turns, rounding the result to the precision of the input and to the nearest [`Float`].
1723 /// The [`Float`] is taken by reference.
1724 ///
1725 /// See [`Float::acsc_pi`] and [`Float::acsc_with_period_prec_round`]; this function behaves the
1726 /// same way.
1727 ///
1728 /// # Examples
1729 /// ```
1730 /// use malachite_float::Float;
1731 ///
1732 /// let x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
1733 /// assert_eq!((&x).acsc_pi_ref().to_string(), "0.13110");
1734 /// ```
1735 #[inline]
1736 pub fn acsc_pi_ref(&self) -> Self {
1737 self.acsc_with_period_ref(2)
1738 }
1739
1740 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1741 /// half-turns, in place, rounding the result to the specified precision and with the specified
1742 /// rounding mode. An [`Ordering`] is returned, indicating whether the rounded arccosecant is
1743 /// less than, equal to, or greater than the exact arccosecant. Although `NaN`s are not
1744 /// comparable to any [`Float`], whenever this function assigns a `NaN` it also returns `Equal`.
1745 ///
1746 /// This is `acsc_with_period` with a period of 2: see
1747 /// [`Float::acsc_with_period_prec_round_assign`] for the error bounds, the special cases,
1748 /// underflow, and the complexity, with $u = 2$. Either infinity gives a zero of its sign, and
1749 /// an input of $\pm1$ gives $\pm1/2$; both are exact at every precision, and they are the only
1750 /// exact cases. NaN and any $|x|<1$, including the zeros, give NaN. Overflow is not possible,
1751 /// since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
1752 ///
1753 /// # Panics
1754 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1755 /// with the given precision.
1756 ///
1757 /// # Examples
1758 /// ```
1759 /// use malachite_base::rounding_modes::RoundingMode::*;
1760 /// use malachite_float::Float;
1761 /// use std::cmp::Ordering::*;
1762 ///
1763 /// let mut x = Float::from(2.5);
1764 /// let o = x.acsc_pi_prec_round_assign(10, Floor);
1765 /// assert_eq!(x.to_string(), "0.13086");
1766 /// assert_eq!(o, Less);
1767 /// ```
1768 #[inline]
1769 pub fn acsc_pi_prec_round_assign(&mut self, prec: u64, rm: RoundingMode) -> Ordering {
1770 self.acsc_with_period_prec_round_assign(2, prec, rm)
1771 }
1772
1773 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1774 /// half-turns, in place, rounding the result to the nearest value of the specified precision.
1775 /// An [`Ordering`] is returned, indicating whether the rounded arccosecant is less than, equal
1776 /// to, or greater than the exact arccosecant. Although `NaN`s are not comparable to any
1777 /// [`Float`], whenever this function assigns a `NaN` it also returns `Equal`.
1778 ///
1779 /// See [`Float::acsc_pi_prec`] and [`Float::acsc_with_period_prec_round`]; this function
1780 /// behaves the same way.
1781 ///
1782 /// # Panics
1783 /// Panics if `prec` is zero.
1784 ///
1785 /// # Examples
1786 /// ```
1787 /// use malachite_float::Float;
1788 /// use std::cmp::Ordering::*;
1789 ///
1790 /// let mut x = Float::from(2.5);
1791 /// let o = x.acsc_pi_prec_assign(10);
1792 /// assert_eq!(x.to_string(), "0.13110");
1793 /// assert_eq!(o, Greater);
1794 /// ```
1795 #[inline]
1796 pub fn acsc_pi_prec_assign(&mut self, prec: u64) -> Ordering {
1797 self.acsc_with_period_prec_assign(2, prec)
1798 }
1799
1800 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1801 /// half-turns, in place, rounding the result with the specified rounding mode. The precision of
1802 /// the output is the precision of the input. An [`Ordering`] is returned, indicating whether
1803 /// the rounded arccosecant is less than, equal to, or greater than the exact arccosecant.
1804 /// Although `NaN`s are not comparable to any [`Float`], whenever this function assigns a `NaN`
1805 /// it also returns `Equal`.
1806 ///
1807 /// See [`Float::acsc_pi_round`] and [`Float::acsc_with_period_prec_round`]; this function
1808 /// behaves the same way.
1809 ///
1810 /// # Panics
1811 /// Panics if `rm` is `Exact` but the result cannot be represented exactly with the precision of
1812 /// the input.
1813 ///
1814 /// # Examples
1815 /// ```
1816 /// use malachite_base::rounding_modes::RoundingMode::*;
1817 /// use malachite_float::Float;
1818 /// use std::cmp::Ordering::*;
1819 ///
1820 /// let mut x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
1821 /// let o = x.acsc_pi_round_assign(Floor);
1822 /// assert_eq!(x.to_string(), "0.13086");
1823 /// assert_eq!(o, Less);
1824 /// ```
1825 #[inline]
1826 pub fn acsc_pi_round_assign(&mut self, rm: RoundingMode) -> Ordering {
1827 self.acsc_with_period_round_assign(2, rm)
1828 }
1829
1830 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Float`] measured in
1831 /// half-turns, in place, rounding the result to the precision of the input and to the nearest
1832 /// [`Float`].
1833 ///
1834 /// If the arccosecant is equidistant from two [`Float`]s with the precision of the input, the
1835 /// [`Float`] with fewer 1s in its binary expansion is chosen. See [`RoundingMode`] for a
1836 /// description of the `Nearest` rounding mode.
1837 ///
1838 /// See [`Float::acsc_pi`] and [`Float::acsc_with_period_prec_round`]; this function behaves the
1839 /// same way.
1840 ///
1841 /// # Examples
1842 /// ```
1843 /// use malachite_float::Float;
1844 ///
1845 /// let mut x = Float::from_unsigned_prec(5u32, 10).0 >> 1u32;
1846 /// x.acsc_pi_assign();
1847 /// assert_eq!(x.to_string(), "0.13110");
1848 /// ```
1849 #[inline]
1850 pub fn acsc_pi_assign(&mut self) {
1851 self.acsc_with_period_assign(2);
1852 }
1853
1854 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Rational`] measured in
1855 /// half-turns, rounding the result to the specified precision and with the specified rounding
1856 /// mode and returning the result as a [`Float`]. The [`Rational`] is taken by value. An
1857 /// [`Ordering`] is also returned, indicating whether the rounded arccosecant is less than,
1858 /// equal to, or greater than the exact arccosecant.
1859 ///
1860 /// This is `acsc_with_period_rational` with a period of 2: see
1861 /// [`Float::acsc_with_period_rational_prec_round`] for the error bounds, the special cases,
1862 /// underflow, and the complexity, with $u = 2$. An input of $\pm1$ gives $\pm1/2$; both are
1863 /// exact at every precision, and they are the only exact cases, the infinities that give a zero
1864 /// being out of a [`Rational`]'s reach. Any $|x|<1$ gives NaN. Overflow is not possible, since
1865 /// $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
1866 ///
1867 /// # Panics
1868 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1869 /// with the given precision.
1870 ///
1871 /// # Examples
1872 /// ```
1873 /// use malachite_base::num::basic::traits::NegativeOne;
1874 /// use malachite_base::rounding_modes::RoundingMode::*;
1875 /// use malachite_float::Float;
1876 /// use malachite_q::Rational;
1877 /// use std::cmp::Ordering::*;
1878 ///
1879 /// // an input of -1 is minus a quarter turn, half a half-turn
1880 /// let (c, o) = Float::acsc_pi_rational_prec_round(Rational::NEGATIVE_ONE, 10, Exact);
1881 /// assert_eq!(c.to_string(), "-0.50000");
1882 /// assert_eq!(o, Equal);
1883 ///
1884 /// let (c, o) =
1885 /// Float::acsc_pi_rational_prec_round(Rational::from_unsigneds(5u8, 3), 10, Floor);
1886 /// assert_eq!(c.to_string(), "0.20459");
1887 /// assert_eq!(o, Less);
1888 /// ```
1889 #[inline]
1890 pub fn acsc_pi_rational_prec_round(
1891 x: Rational,
1892 prec: u64,
1893 rm: RoundingMode,
1894 ) -> (Self, Ordering) {
1895 Self::acsc_with_period_rational_prec_round(x, 2, prec, rm)
1896 }
1897
1898 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Rational`] measured in
1899 /// half-turns, rounding the result to the specified precision and with the specified rounding
1900 /// mode and returning the result as a [`Float`]. The [`Rational`] is taken by reference. An
1901 /// [`Ordering`] is also returned, indicating whether the rounded arccosecant is less than,
1902 /// equal to, or greater than the exact arccosecant.
1903 ///
1904 /// See [`Float::acsc_pi_rational_prec_round`] and
1905 /// [`Float::acsc_with_period_rational_prec_round_ref`]; this function behaves the same way.
1906 ///
1907 /// # Panics
1908 /// Panics if `prec` is zero, or if `rm` is `Exact` but the result cannot be represented exactly
1909 /// with the given precision.
1910 ///
1911 /// # Examples
1912 /// ```
1913 /// use malachite_base::rounding_modes::RoundingMode::*;
1914 /// use malachite_float::Float;
1915 /// use malachite_q::Rational;
1916 /// use std::cmp::Ordering::*;
1917 ///
1918 /// let (c, o) =
1919 /// Float::acsc_pi_rational_prec_round_ref(&Rational::from_unsigneds(5u8, 3), 10, Ceiling);
1920 /// assert_eq!(c.to_string(), "0.20483");
1921 /// assert_eq!(o, Greater);
1922 /// ```
1923 #[inline]
1924 pub fn acsc_pi_rational_prec_round_ref(
1925 x: &Rational,
1926 prec: u64,
1927 rm: RoundingMode,
1928 ) -> (Self, Ordering) {
1929 Self::acsc_with_period_rational_prec_round_ref(x, 2, prec, rm)
1930 }
1931
1932 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Rational`] measured in
1933 /// half-turns, rounding the result to the nearest value of the specified precision and
1934 /// returning the result as a [`Float`]. The [`Rational`] is taken by value. An [`Ordering`] is
1935 /// also returned, indicating whether the rounded arccosecant is less than, equal to, or greater
1936 /// than the exact arccosecant.
1937 ///
1938 /// See [`Float::acsc_pi_rational_prec_round`] and [`Float::acsc_with_period_rational_prec`];
1939 /// this function behaves the same way.
1940 ///
1941 /// # Panics
1942 /// Panics if `prec` is zero.
1943 ///
1944 /// # Examples
1945 /// ```
1946 /// use malachite_float::Float;
1947 /// use malachite_q::Rational;
1948 /// use std::cmp::Ordering::*;
1949 ///
1950 /// let (c, o) = Float::acsc_pi_rational_prec(Rational::from_unsigneds(5u8, 3), 53);
1951 /// assert_eq!(c.to_string(), "0.20483276469913345");
1952 /// assert_eq!(o, Less);
1953 /// ```
1954 #[inline]
1955 pub fn acsc_pi_rational_prec(x: Rational, prec: u64) -> (Self, Ordering) {
1956 Self::acsc_with_period_rational_prec(x, 2, prec)
1957 }
1958
1959 /// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Rational`] measured in
1960 /// half-turns, rounding the result to the nearest value of the specified precision and
1961 /// returning the result as a [`Float`]. The [`Rational`] is taken by reference. An [`Ordering`]
1962 /// is also returned, indicating whether the rounded arccosecant is less than, equal to, or
1963 /// greater than the exact arccosecant.
1964 ///
1965 /// See [`Float::acsc_pi_rational_prec`] and [`Float::acsc_with_period_rational_prec_ref`]; this
1966 /// function behaves the same way.
1967 ///
1968 /// # Panics
1969 /// Panics if `prec` is zero.
1970 ///
1971 /// # Examples
1972 /// ```
1973 /// use malachite_float::Float;
1974 /// use malachite_q::Rational;
1975 /// use std::cmp::Ordering::*;
1976 ///
1977 /// let (c, o) = Float::acsc_pi_rational_prec_ref(&Rational::from_unsigneds(5u8, 3), 53);
1978 /// assert_eq!(c.to_string(), "0.20483276469913345");
1979 /// assert_eq!(o, Less);
1980 /// ```
1981 #[inline]
1982 pub fn acsc_pi_rational_prec_ref(x: &Rational, prec: u64) -> (Self, Ordering) {
1983 Self::acsc_with_period_rational_prec_ref(x, 2, prec)
1984 }
1985}
1986
1987impl Acsc for Float {
1988 type Output = Self;
1989
1990 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], taking it by value.
1991 ///
1992 /// If the output has a precision, it is the precision of the input. If the arccosecant is
1993 /// equidistant from two [`Float`]s with the specified precision, the [`Float`] with fewer 1s in
1994 /// its binary expansion is chosen. See [`RoundingMode`] for a description of the `Nearest`
1995 /// rounding mode.
1996 ///
1997 /// $$
1998 /// f(x) = \operatorname{acsc}(x)+\varepsilon.
1999 /// $$
2000 /// - If $x$ is NaN, infinite, or $|x|<1$, $\varepsilon$ may be ignored or assumed to be 0.
2001 /// - Otherwise, $|\varepsilon| \leq 2^{\lfloor\log_2 |\operatorname{acsc}(x)|\rfloor-p}$, where
2002 /// $p$ is the precision of the input.
2003 ///
2004 /// Special cases:
2005 /// - $f(\text{NaN})=\text{NaN}$
2006 /// - $f(x)=\text{NaN}$ for $|x|<1$, including $\pm0.0$
2007 /// - $f(\infty)=0.0$ and $f(-\infty)=-0.0$
2008 /// - $f(1)=\pi/2$ and $f(-1)=-\pi/2$
2009 ///
2010 /// Overflow and underflow are both impossible; see [`Float::acsc_prec_round`].
2011 ///
2012 /// If you want to specify an output precision, consider using [`Float::acsc_prec`] instead. If
2013 /// you want to specify a rounding mode as well, consider using [`Float::acsc_prec_round`].
2014 ///
2015 /// # Worst-case complexity
2016 /// $T(n, m) = O(n (\log n)^3 \log\log n + m \log m \log\log m)$
2017 ///
2018 /// $M(n, m) = O(n \log n + m \log m)$
2019 ///
2020 /// where $T$ is time, $M$ is additional memory, $n$ is the precision of the input, and $m$ is
2021 /// `self.significant_bits()`.
2022 ///
2023 /// # Examples
2024 /// ```
2025 /// use malachite_base::num::arithmetic::traits::Acsc;
2026 /// use malachite_base::num::basic::traits::Two;
2027 /// use malachite_float::Float;
2028 ///
2029 /// assert_eq!(Float::TWO.acsc().to_string(), "0.50");
2030 /// ```
2031 #[inline]
2032 fn acsc(self) -> Self {
2033 let prec = self.significant_bits();
2034 self.acsc_prec(prec).0
2035 }
2036}
2037
2038impl Acsc for &Float {
2039 type Output = Float;
2040
2041 /// Computes $\operatorname{acsc} x$, the arccosecant of a [`Float`], taking it by reference.
2042 ///
2043 /// See [`Acsc::acsc`] and [`Float::acsc_prec_round`]; this function behaves the same way.
2044 ///
2045 /// # Worst-case complexity
2046 /// $T(n, m) = O(n (\log n)^3 \log\log n + m \log m \log\log m)$
2047 ///
2048 /// $M(n, m) = O(n \log n + m \log m)$
2049 ///
2050 /// where $T$ is time, $M$ is additional memory, $n$ is the precision of the input, and $m$ is
2051 /// `self.significant_bits()`.
2052 ///
2053 /// # Examples
2054 /// ```
2055 /// use malachite_base::num::arithmetic::traits::Acsc;
2056 /// use malachite_base::num::basic::traits::Two;
2057 /// use malachite_float::Float;
2058 ///
2059 /// assert_eq!((&Float::TWO).acsc().to_string(), "0.50");
2060 /// ```
2061 #[inline]
2062 fn acsc(self) -> Float {
2063 self.acsc_prec_ref(self.significant_bits()).0
2064 }
2065}
2066
2067impl AcscAssign for Float {
2068 /// Replaces a [`Float`] with its arccosecant, $\operatorname{acsc}(x)$.
2069 ///
2070 /// See [`Acsc::acsc`] and [`Float::acsc_prec_round`]; this function behaves the same way.
2071 ///
2072 /// # Worst-case complexity
2073 /// $T(n, m) = O(n (\log n)^3 \log\log n + m \log m \log\log m)$
2074 ///
2075 /// $M(n, m) = O(n \log n + m \log m)$
2076 ///
2077 /// where $T$ is time, $M$ is additional memory, $n$ is the precision of the input, and $m$ is
2078 /// `self.significant_bits()`.
2079 ///
2080 /// # Examples
2081 /// ```
2082 /// use malachite_base::num::arithmetic::traits::AcscAssign;
2083 /// use malachite_base::num::basic::traits::Two;
2084 /// use malachite_float::Float;
2085 ///
2086 /// let mut x = Float::TWO;
2087 /// x.acsc_assign();
2088 /// assert_eq!(x.to_string(), "0.50");
2089 /// ```
2090 #[inline]
2091 fn acsc_assign(&mut self) {
2092 let prec = self.significant_bits();
2093 self.acsc_prec_assign(prec);
2094 }
2095}
2096
2097/// Computes $\operatorname{acsc} x$, the arccosecant of a primitive float, returning the result as
2098/// a primitive float.
2099///
2100/// This is the correctly rounded arccosecant: the exact $\operatorname{acsc}(x)$ is rounded once,
2101/// to the nearest value of the input's type.
2102///
2103/// Special cases:
2104/// - $f(\text{NaN})=\text{NaN}$
2105/// - $f(x)=\text{NaN}$ for $|x|<1$, including $\pm0.0$
2106/// - $f(\infty)=0.0$ and $f(-\infty)=-0.0$
2107///
2108/// Overflow is not possible, since $|\operatorname{acsc}(x)| \leq \pi/2$, and neither is underflow:
2109/// a primitive float's exponent is bounded, so $1/|x|$ stays well inside the normal range.
2110///
2111/// # Worst-case complexity
2112/// $T(m) = O(m \log m \log\log m)$
2113///
2114/// $M(m) = O(m \log m)$
2115///
2116/// where $T$ is time, $M$ is additional memory, and $m$ is `x.significant_bits()`.
2117///
2118/// # Examples
2119/// ```
2120/// use malachite_base::num::float::NiceFloat;
2121/// use malachite_float::float::arithmetic::acsc::primitive_float_acsc;
2122///
2123/// assert!(primitive_float_acsc(f32::NAN).is_nan());
2124/// // the arccosecant is NaN inside (-1, 1)
2125/// assert!(primitive_float_acsc(0.5f32).is_nan());
2126/// assert_eq!(
2127/// NiceFloat(primitive_float_acsc(f32::INFINITY)),
2128/// NiceFloat(0.0)
2129/// );
2130/// assert_eq!(
2131/// NiceFloat(primitive_float_acsc(2.0f32)),
2132/// NiceFloat(0.5235988)
2133/// );
2134/// assert_eq!(
2135/// NiceFloat(primitive_float_acsc(-2.0f32)),
2136/// NiceFloat(-0.5235988)
2137/// );
2138/// assert_eq!(
2139/// NiceFloat(primitive_float_acsc(2.0f64)),
2140/// NiceFloat(0.5235987755982989)
2141/// );
2142/// ```
2143#[inline]
2144#[allow(clippy::type_repetition_in_bounds)]
2145pub fn primitive_float_acsc<T: PrimitiveFloat>(x: T) -> T
2146where
2147 Float: From<T> + PartialOrd<T>,
2148 for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
2149{
2150 emulate_float_to_float_fn(Float::acsc_prec, x)
2151}
2152
2153/// Computes $\operatorname{acsc} x$, the arccosecant of a [`Rational`], returning the result as a
2154/// primitive float.
2155///
2156/// This is the correctly rounded arccosecant: the exact $\operatorname{acsc}(x)$ is rounded once,
2157/// to the nearest value of the output type.
2158///
2159/// Special cases:
2160/// - $f(x)=\text{NaN}$ for $|x|<1$, including zero
2161///
2162/// Overflow is not possible, since $|\operatorname{acsc}(x)| \leq \pi/2$. The result is subnormal,
2163/// or zero, only when $|x|$ is large enough to put $1/|x|$ below the bottom of the output type's
2164/// normal range.
2165///
2166/// # Worst-case complexity
2167/// $T(m) = O(m \log m \log\log m)$
2168///
2169/// $M(m) = O(m \log m)$
2170///
2171/// where $T$ is time, $M$ is additional memory, and $m$ is `x.significant_bits()`.
2172///
2173/// # Examples
2174/// ```
2175/// use malachite_base::num::basic::traits::{NegativeOne, One, OneHalf, Two};
2176/// use malachite_base::num::float::NiceFloat;
2177/// use malachite_float::float::arithmetic::acsc::primitive_float_acsc_rational;
2178/// use malachite_q::Rational;
2179///
2180/// // the arccosecant is NaN inside (-1, 1)
2181/// assert!(primitive_float_acsc_rational::<f64>(&Rational::ONE_HALF).is_nan());
2182/// assert_eq!(
2183/// NiceFloat(primitive_float_acsc_rational::<f64>(&Rational::ONE)),
2184/// NiceFloat(1.5707963267948966)
2185/// );
2186/// assert_eq!(
2187/// NiceFloat(primitive_float_acsc_rational::<f64>(
2188/// &Rational::NEGATIVE_ONE
2189/// )),
2190/// NiceFloat(-1.5707963267948966)
2191/// );
2192/// assert_eq!(
2193/// NiceFloat(primitive_float_acsc_rational::<f64>(&Rational::TWO)),
2194/// NiceFloat(0.5235987755982989)
2195/// );
2196/// assert_eq!(
2197/// NiceFloat(primitive_float_acsc_rational::<f32>(
2198/// &Rational::from_unsigneds(5u8, 3)
2199/// )),
2200/// NiceFloat(0.6435011)
2201/// );
2202/// ```
2203#[inline]
2204#[allow(clippy::type_repetition_in_bounds)]
2205pub fn primitive_float_acsc_rational<T: PrimitiveFloat>(x: &Rational) -> T
2206where
2207 Float: PartialOrd<T>,
2208 for<'a> T: ExactFrom<&'a Float>,
2209{
2210 emulate_rational_to_float_fn(Float::acsc_rational_prec_ref, x)
2211}
2212
2213/// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a primitive float measured in
2214/// $u$ths of a turn (so that `u = 360` gives degrees), returning the result as a primitive float.
2215///
2216/// This is `primitive_float_acsc` scaled by $u/(2\pi)$: see [`Float::acsc_with_period_prec_round`]
2217/// for the error bounds and the special cases. NaN and every $|x|<1$, including the zeros, give
2218/// NaN, even when $u=0$; $\pm\infty$ give $\pm0.0$; a zero period gives a zero with the sign of
2219/// $x$; $\pm1$ give $\pm u/4$; and $\pm2$ give $\pm u/12$ when $u$ is a multiple of 3.
2220///
2221/// Overflow is not possible, since $|f(x,u)| \leq u/4 < 2^{62}$. The result is subnormal, or zero,
2222/// only when $u$ is small and $|x|$ is large enough to put $u/(2\pi|x|)$ below the bottom of the
2223/// type's normal range.
2224///
2225/// # Worst-case complexity
2226/// $T(m) = O(m \log m \log\log m)$
2227///
2228/// $M(m) = O(m \log m)$
2229///
2230/// where $T$ is time, $M$ is additional memory, and $m$ is `x.significant_bits()`.
2231///
2232/// # Examples
2233/// ```
2234/// use malachite_base::num::float::NiceFloat;
2235/// use malachite_float::float::arithmetic::acsc::primitive_float_acsc_with_period;
2236///
2237/// assert!(primitive_float_acsc_with_period(f32::NAN, 360).is_nan());
2238/// // the arccosecant is NaN inside (-1, 1)
2239/// assert!(primitive_float_acsc_with_period(0.5f32, 360).is_nan());
2240/// assert_eq!(
2241/// NiceFloat(primitive_float_acsc_with_period(f32::INFINITY, 360)),
2242/// NiceFloat(0.0)
2243/// );
2244/// // an input of 2 is a twelfth of a turn, and one of -1 minus a quarter
2245/// assert_eq!(
2246/// NiceFloat(primitive_float_acsc_with_period(2.0f32, 360)),
2247/// NiceFloat(30.0)
2248/// );
2249/// assert_eq!(
2250/// NiceFloat(primitive_float_acsc_with_period(-1.0f32, 360)),
2251/// NiceFloat(-90.0)
2252/// );
2253/// assert_eq!(
2254/// NiceFloat(primitive_float_acsc_with_period(2.5f64, 360)),
2255/// NiceFloat(23.57817847820183)
2256/// );
2257/// ```
2258#[inline]
2259#[allow(clippy::type_repetition_in_bounds)]
2260pub fn primitive_float_acsc_with_period<T: PrimitiveFloat>(x: T, u: u64) -> T
2261where
2262 Float: From<T> + PartialOrd<T>,
2263 for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
2264{
2265 emulate_float_to_float_fn(|x, prec| Float::acsc_with_period_prec(x, u, prec), x)
2266}
2267
2268/// Computes $\operatorname{acsc}(x)u/(2\pi)$, the arccosecant of a [`Rational`] measured in $u$ths
2269/// of a turn (so that `u = 360` gives degrees), returning the result as a primitive float.
2270///
2271/// This is `primitive_float_acsc_rational` scaled by $u/(2\pi)$: see
2272/// [`Float::acsc_with_period_rational_prec_round`] for the error bounds and the special cases.
2273/// Every $|x|<1$ gives NaN, even when $u=0$; a zero period gives a zero with the sign of $x$;
2274/// $\pm1$ give $\pm u/4$; and $\pm2$ give $\pm u/12$ when $u$ is a multiple of 3.
2275///
2276/// Overflow is not possible, since $|f(x,u)| \leq u/4 < 2^{62}$. The result is subnormal, or zero,
2277/// only when $u$ is small and $|x|$ is large enough to put $u/(2\pi|x|)$ below the bottom of the
2278/// type's normal range.
2279///
2280/// # Worst-case complexity
2281/// $T(m) = O(m \log m \log\log m)$
2282///
2283/// $M(m) = O(m \log m)$
2284///
2285/// where $T$ is time, $M$ is additional memory, and $m$ is `x.significant_bits()`.
2286///
2287/// # Examples
2288/// ```
2289/// use malachite_base::num::basic::traits::{NegativeOne, OneHalf, Two};
2290/// use malachite_base::num::float::NiceFloat;
2291/// use malachite_float::float::arithmetic::acsc::primitive_float_acsc_with_period_rational;
2292/// use malachite_q::Rational;
2293///
2294/// // the arccosecant is NaN inside (-1, 1)
2295/// assert!(primitive_float_acsc_with_period_rational::<f64>(&Rational::ONE_HALF, 360).is_nan());
2296/// // an input of 2 is a twelfth of a turn, and one of -1 minus a quarter
2297/// assert_eq!(
2298/// NiceFloat(primitive_float_acsc_with_period_rational::<f64>(
2299/// &Rational::TWO,
2300/// 360
2301/// )),
2302/// NiceFloat(30.0)
2303/// );
2304/// assert_eq!(
2305/// NiceFloat(primitive_float_acsc_with_period_rational::<f64>(
2306/// &Rational::NEGATIVE_ONE,
2307/// 360
2308/// )),
2309/// NiceFloat(-90.0)
2310/// );
2311/// assert_eq!(
2312/// NiceFloat(primitive_float_acsc_with_period_rational::<f64>(
2313/// &Rational::from_unsigneds(5u8, 3),
2314/// 360
2315/// )),
2316/// NiceFloat(36.86989764584402)
2317/// );
2318/// ```
2319#[inline]
2320#[allow(clippy::type_repetition_in_bounds)]
2321pub fn primitive_float_acsc_with_period_rational<T: PrimitiveFloat>(x: &Rational, u: u64) -> T
2322where
2323 Float: PartialOrd<T>,
2324 for<'a> T: ExactFrom<&'a Float>,
2325{
2326 emulate_rational_to_float_fn(
2327 |x, prec| Float::acsc_with_period_rational_prec_ref(x, u, prec),
2328 x,
2329 )
2330}
2331
2332/// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a primitive float measured in
2333/// half-turns, returning the result as a primitive float.
2334///
2335/// This is `primitive_float_acsc_with_period` with a period of 2: see
2336/// [`primitive_float_acsc_with_period`] for the error bounds, the special cases, and the
2337/// complexity, with $u = 2$. Either infinity gives a zero of its sign, and an input of $\pm1$ gives
2338/// $\pm1/2$; NaN and any $|x|<1$, including the zeros, give NaN. Overflow is not possible, since
2339/// $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
2340///
2341/// # Worst-case complexity
2342/// $T(m) = O(m \log m \log\log m)$
2343///
2344/// $M(m) = O(m \log m)$
2345///
2346/// where $T$ is time, $M$ is additional memory, and $m$ is `x.significant_bits()`.
2347///
2348/// # Examples
2349/// ```
2350/// use malachite_base::num::float::NiceFloat;
2351/// use malachite_float::float::arithmetic::acsc::primitive_float_acsc_pi;
2352///
2353/// assert!(primitive_float_acsc_pi(f32::NAN).is_nan());
2354/// // the arccosecant is NaN inside (-1, 1)
2355/// assert!(primitive_float_acsc_pi(0.5f32).is_nan());
2356/// assert_eq!(
2357/// NiceFloat(primitive_float_acsc_pi(f32::INFINITY)),
2358/// NiceFloat(0.0)
2359/// );
2360/// assert_eq!(NiceFloat(primitive_float_acsc_pi(1.0f32)), NiceFloat(0.5));
2361/// assert_eq!(NiceFloat(primitive_float_acsc_pi(-1.0f32)), NiceFloat(-0.5));
2362/// assert_eq!(
2363/// NiceFloat(primitive_float_acsc_pi(2.5f32)),
2364/// NiceFloat(0.13098988)
2365/// );
2366/// assert_eq!(
2367/// NiceFloat(primitive_float_acsc_pi(2.5f64)),
2368/// NiceFloat(0.13098988043445461)
2369/// );
2370/// ```
2371#[inline]
2372#[allow(clippy::type_repetition_in_bounds)]
2373pub fn primitive_float_acsc_pi<T: PrimitiveFloat>(x: T) -> T
2374where
2375 Float: From<T> + PartialOrd<T>,
2376 for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float>,
2377{
2378 primitive_float_acsc_with_period(x, 2)
2379}
2380
2381/// Computes $\operatorname{acsc}(x)/\pi$, the arccosecant of a [`Rational`] measured in half-turns,
2382/// returning the result as a primitive float.
2383///
2384/// This is `primitive_float_acsc_with_period_rational` with a period of 2: see
2385/// [`primitive_float_acsc_with_period_rational`] for the error bounds, the special cases, and the
2386/// complexity, with $u = 2$. An input of $\pm1$ gives $\pm1/2$; any $|x|<1$ gives NaN. Overflow is
2387/// not possible, since $|\operatorname{acsc}(x)/\pi| \leq 1/2$.
2388///
2389/// # Worst-case complexity
2390/// $T(m) = O(m \log m \log\log m)$
2391///
2392/// $M(m) = O(m \log m)$
2393///
2394/// where $T$ is time, $M$ is additional memory, and $m$ is `x.significant_bits()`.
2395///
2396/// # Examples
2397/// ```
2398/// use malachite_base::num::basic::traits::{NegativeOne, One, OneHalf};
2399/// use malachite_base::num::float::NiceFloat;
2400/// use malachite_float::float::arithmetic::acsc::primitive_float_acsc_pi_rational;
2401/// use malachite_q::Rational;
2402///
2403/// // the arccosecant is NaN inside (-1, 1)
2404/// assert!(primitive_float_acsc_pi_rational::<f64>(&Rational::ONE_HALF).is_nan());
2405/// assert_eq!(
2406/// NiceFloat(primitive_float_acsc_pi_rational::<f64>(&Rational::ONE)),
2407/// NiceFloat(0.5)
2408/// );
2409/// assert_eq!(
2410/// NiceFloat(primitive_float_acsc_pi_rational::<f64>(
2411/// &Rational::NEGATIVE_ONE
2412/// )),
2413/// NiceFloat(-0.5)
2414/// );
2415/// assert_eq!(
2416/// NiceFloat(primitive_float_acsc_pi_rational::<f64>(
2417/// &Rational::from_unsigneds(5u8, 3)
2418/// )),
2419/// NiceFloat(0.20483276469913345)
2420/// );
2421/// assert_eq!(
2422/// NiceFloat(primitive_float_acsc_pi_rational::<f32>(
2423/// &Rational::from_unsigneds(5u8, 3)
2424/// )),
2425/// NiceFloat(0.20483276)
2426/// );
2427/// ```
2428#[inline]
2429#[allow(clippy::type_repetition_in_bounds)]
2430pub fn primitive_float_acsc_pi_rational<T: PrimitiveFloat>(x: &Rational) -> T
2431where
2432 Float: PartialOrd<T>,
2433 for<'a> T: ExactFrom<&'a Float>,
2434{
2435 primitive_float_acsc_with_period_rational(x, 2)
2436}