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