devela/num/float/ext_float.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
// devela::num::float::ext_float
//
//! Extention trait for floatin-point methods.
//
// IMPROVE: remove redundant methods implemented in `core`
use super::shared_docs::*;
#[cfg(_float··)]
use crate::Float;
use crate::{ExtFloatConst, Sign};
/// Extension trait for floating-point types. Associated methods.
///
/// This trait can be more convenient to use than the [`Float`] struct,
/// for non-const operations over primitive floating-point types.
///
/// # Features
/// It depends on having any `_float_f[32|64]` features enabled.
///
/// `Float` has a few more methods implemented if the `dep_libm` feature is enabled.
#[rustfmt::skip]
pub trait ExtFloat: ExtFloatConst + Sized {
/// The largest integer less than or equal to `self`.
///
/// # Formula
#[doc = FORMULA_FLOOR!()]
#[must_use]
fn floor(self) -> Self;
/// The smallest integer greater than or equal to `self`.
///
/// # Formula
#[doc = FORMULA_CEIL!()]
#[must_use]
fn ceil(self) -> Self;
/// The nearest integer to `self`, default rounding, same as
/// [`round_ties_away`][ExtFloat::round_ties_away]
#[must_use]
fn round(self) -> Self;
/// The nearest integer to `self`, rounding ties away from `0.0`.
///
/// # Formula
#[doc = FORMULA_ROUND_TIES_AWAY!()]
#[must_use]
fn round_ties_away(self) -> Self;
/// The nearest integer to `self`, rounding ties to the nearest even integer.
///
/// # Formula
#[doc = FORMULA_ROUND_TIES_EVEN!()]
#[must_use]
fn round_ties_even(self) -> Self;
/// The nearest integer to `self`, rounding ties to the nearest odd integer.
///
/// # Formula
#[doc = FORMULA_ROUND_TIES_ODD!()]
#[must_use]
fn round_ties_odd(self) -> Self;
/// The integral part of `self`.
///
/// # Formula
#[doc = FORMULA_TRUNC!()]
#[must_use]
fn trunc(self) -> Self;
/// The fractional part of `self`.
///
/// # Formula
#[doc = FORMULA_FRACT!()]
#[must_use]
fn fract(self) -> Self;
/// The integral and fractional parts ox `self`.
///
/// # Formula
#[doc = FORMULA_SPLIT!()]
#[must_use]
fn split(self) -> (Self, Self);
/// The absolute value of `self`.
#[must_use]
fn abs(self) -> Self;
/// The negative absolute value of `self`.
#[must_use]
fn neg_abs(self) -> Self;
/// Returns the `Sign` of `self`.
#[must_use]
fn sign(self) -> Sign;
/// Returns the `Sign` of `self`, except for zero.
#[must_use]
fn sign_nonzero(self) -> Sign;
/// A number that represents the sign of `self`.
#[must_use]
fn signum(self) -> Self;
/// Flips the sign of `self`.
#[must_use]
fn flip_sign(self) -> Self;
/// Returns `true` if `self` has a positive sign.
#[must_use]
fn is_sign_positive(self) -> bool;
/// Returns `true` if `self` has a negative sign.
#[must_use]
fn is_sign_negative(self) -> bool;
/// Returns `true` if `self` is either 0.0 or -0.0.
#[must_use]
fn is_zero(self) -> bool;
/// Returns `true` if `self` has a positive sign and is not zero.
#[must_use]
fn is_sign_positive_nonzero(self) -> bool;
/// Returns `true` if `self` has a negative sign and is not zero.
#[must_use]
fn is_sign_negative_nonzero(self) -> bool;
/// A number composed of a magnitude of `self` and the sign of `sign`.
#[must_use]
fn copysign(self, sign: Self) -> Self;
/// Fused multiply-add. Computes `(self * mul) + add` with only one rounding error.
///
/// With either `std` or `dep_libm` enabled it leverages compiler intrinsics,
/// otherwise it uses [`mul_add_fallback`][Float::mul_add_fallback].
#[must_use]
fn mul_add(self, mul: Self, add: Self) -> Self;
/// The euclidean division.
#[must_use]
fn div_euclid(self, rhs: Self) -> Self;
/// The least nonnegative remainder of `self % rhs`.
#[must_use]
fn rem_euclid(self, rhs: Self) -> Self;
/// Returns `self` between `[min..=max]` scaled to a new range `[u..=v]`.
///
/// Values of `self` outside `[min..=max]` are not clamped and will result in extrapolation.
/// # Formula
#[doc = FORMULA_SCALE!()]
#[must_use]
fn scale(self, min: Self, max: Self, u: Self, v: Self) -> Self;
/// Calculates a linearly interpolated value between `u..=v`
/// based on the percentage `self` between `[0..=1]`.
///
/// Values of `self` outside `[0..=1]` are not clamped and will result in extrapolation.
/// # Formula
#[doc = FORMULA_LERP!()]
#[must_use]
fn lerp(self, u: Self, v: Self) -> Self;
/// Raises `self` to the `y` floating point power.
///
/// With either `std` or `dep_libm` enabled it leverages compiler intrinsics,
/// otherwise it's equal to [`powf_series`][Float::powf_series].
#[must_use]
fn powf(self, y: Self) -> Self;
/// Raises `self` to the `p` integer power.
#[must_use]
fn powi(self, p: i32) -> Self;
/// The square root.
///
/// With either `std` or `dep_libm` enabled it leverages compiler intrinsics,
/// otherwise it's equal to [`sqrt_nr`][Float::sqrt_nr].
#[must_use]
fn sqrt(self) -> Self;
/// The square root calculated using the
/// [fast inverse square root algorithm](https://en.wikipedia.org/wiki/Fast_inverse_square_root).
#[must_use]
fn sqrt_fisr(self) -> Self;
/// $ 1 / \sqrt{x} $ the
/// [fast inverse square root algorithm](https://en.wikipedia.org/wiki/Fast_inverse_square_root).
#[must_use]
fn fisr(self) -> Self;
/// The cubic root.
///
/// With either `std` or `dep_libm` enabled it leverages compiler intrinsics,
/// otherwise it's equal to [`cbrt_nr`][Float::cbrt_nr].
#[must_use]
fn cbrt(self) -> Self;
/// The hypothenuse (the euclidean distance).
///
/// With either `std` or `dep_libm` enabled it leverages compiler intrinsics,
/// otherwise it's equal to [`hypot_nr`][Float::hypot_nr].
#[must_use]
fn hypot(self, rhs: Self) -> Self;
/// $e^x$ (the exponential function).
///
/// The maximum values with a representable result are:
/// 88.722… for `f32` and 709.782… for `f64`.
///
/// With both `std` and `dep_libm` disabled it leverages [`exp_series`][Float::exp_series]
/// with [`exp_series_terms`][Float::exp_series_terms].
#[must_use]
fn exp(self) -> Self;
/// $2^x$.
///
/// With both `std` and `dep_libm` disabled it leverages [`exp2_series`][Float::exp2_series]
/// with [`exp2_series_terms`][Float::exp2_series_terms].
#[must_use]
fn exp2(self) -> Self;
/// The exponential minus 1, more accurately.
///
/// With both `std` and `dep_libm` disabled it leverages [`exp_m1_series`][Float::exp_m1_series]
/// with [`exp_series_terms`][Float::exp_series_terms].
#[must_use]
fn exp_m1(self) -> Self;
/// The natural logarithm of `self`.
///
/// With both `std` and `dep_libm` disabled it leverages [`ln_series`][Float::ln_series]
/// with [`ln_series_terms`][Float::ln_series_terms].
#[must_use]
fn ln(self) -> Self;
/// The natural logarithm of `self` plus 1, more accurately.
///
/// With both `std` and `dep_libm` disabled it leverages [`ln_1p_series`][Float::ln_1p_series]
/// with [`ln_series_terms`][Float::ln_series_terms].
#[must_use]
fn ln_1p(self) -> Self;
/// The logarithm of `self` with respect to an arbitrary `base`.
///
/// With both `std` and `dep_libm` disabled it leverages [`log_series`][Float::log_series]
/// with [`ln_series_terms`][Float::ln_series_terms].
#[must_use]
fn log(self, base: Self) -> Self;
/// The base 2 logarithm of `self`.
///
/// With both `std` and `dep_libm` disabled it leverages [`log2_series`][Float::log2_series]
/// with [`ln_series_terms`][Float::ln_series_terms].
#[must_use]
fn log2(self) -> Self;
/// The base 10 logarithm of `self`.
///
/// With both `std` and `dep_libm` disabled it leverages [`log10_series`][Float::log10_series]
/// with [`ln_series_terms`][Float::ln_series_terms].
#[must_use]
fn log10(self) -> Self;
/// The factorial.
///
/// The maximum values with a representable result are:
/// 34 for `f32` and 170 for `f64`.
#[must_use]
fn factorial(n: u32) -> Self;
/// The sine.
///
/// With both `std` and `dep_libm` disabled it leverages
/// [`sin_series`][Float::sin_series] with 8 terms.
#[must_use]
fn sin(self) -> Self;
/// The cosine.
///
/// With both `std` and `dep_libm` disabled it leverages
/// [`cos_series`][Float::cos_series] with 8 terms.
#[must_use]
fn cos(self) -> Self;
/// Both the sine and cosine.
///
/// With both `std` and `dep_libm` disabled it leverages
/// [`sin_cos_series`][Float::sin_cos_series] with 8 terms.
#[must_use]
fn sin_cos(self) -> (Self, Self);
/// The tangent.
///
/// With both `std` and `dep_libm` disabled it leverages
/// [`tan_series`][Float::tan_series] with 8 terms.
#[must_use]
fn tan(self) -> Self;
/// The arc sine.
///
/// With both `std` and `dep_libm` disabled it leverages [`asin_series`][Float::asin_series]
/// with [`asin_series_terms`][Float::asin_series_terms].
#[must_use]
fn asin(self) -> Self;
/// The arc cosine.
///
/// With both `std` and `dep_libm` disabled it leverages [`acos_series`][Float::acos_series]
/// with [`acos_series_terms`][Float::acos_series_terms].
#[must_use]
fn acos(self) -> Self;
/// The arc tangent.
///
/// With both `std` and `dep_libm` disabled it leverages [`atan_series`][Float::atan_series]
/// with [`atan_series_terms`][Float::atan_series_terms].
#[must_use]
fn atan(self) -> Self;
/// The arc tangent of two variables.
///
/// With both `std` and `dep_libm` disabled it leverages [`atan2_series`][Float::atan2_series]
/// with [`atan_series_terms`][Float::atan_series_terms].
#[must_use]
fn atan2(self, other: Self) -> Self;
/// The hyperbolic sine.
///
/// With both `std` and `dep_libm` disabled it leverages [`sinh_series`][Float::sinh_series]
/// with [`exp_series_terms`][Float::exp_series_terms].
#[must_use]
fn sinh(self) -> Self;
/// The hyperbolic cosine.
///
/// With both `std` and `dep_libm` disabled it leverages [`cosh_series`][Float::cosh_series]
/// with [`exp_series_terms`][Float::exp_series_terms].
#[must_use]
fn cosh(self) -> Self;
/// The hyperbolic tangent.
///
/// With both `std` and `dep_libm` disabled it leverages [`cosh_series`][Float::cosh_series]
/// with [`exp_series_terms`][Float::exp_series_terms].
#[must_use]
fn tanh(self) -> Self;
/// The inverse hyperbolic sine of `self`.
///
/// With both `std` and `dep_libm` disabled it leverages [`asinh_series`][Float::asinh_series]
/// with [`ln_series_terms`][Float::ln_series_terms].
#[must_use]
fn asinh(self) -> Self;
/// The inverse hyperbolic cosine of `self`.
///
/// With both `std` and `dep_libm` disabled it leverages [`acosh_series`][Float::acosh_series]
/// with [`ln_series_terms`][Float::ln_series_terms].
#[must_use]
fn acosh(self) -> Self;
/// The inverse hyperbolic tangent of `self`.
///
/// With both `std` and `dep_libm` disabled it leverages [`atanh_series`][Float::atanh_series]
/// with [`ln_series_terms`][Float::ln_series_terms].
#[must_use]
fn atanh(self) -> Self;
/// The clamped value, propagating `NaN`.
#[must_use]
fn clamp_nan(self, min: Self, max: Self) -> Self;
/// The maximum of two numbers, propagating `NaN`.
#[must_use]
fn max_nan(self, other: Self) -> Self;
/// The minimum of two numbers, propagating `NaN`.
#[must_use]
fn min_nan(self, other: Self) -> Self;
/// The clamped value, using total order.
///
/// # Features
/// This will only work if the corresponding `_cmp_[f32|f64]` feature is enabled,
/// otherwise it will return `NaN`.
#[must_use]
fn clamp_total(self, min: Self, max: Self) -> Self;
/// The maximum of two numbers using total order.
///
/// # Features
/// This will only work if the corresponding `_cmp_[f32|f64]` feature is enabled,
/// otherwise it will return `NaN`.
#[must_use]
fn max_total(self, other: Self) -> Self;
/// The minimum of two numbers using total order.
///
/// # Features
/// This will only work if the corresponding `_cmp_[f32|f64]` feature is enabled,
/// otherwise it will return `NaN`.
#[must_use]
fn min_total(self, other: Self) -> Self;
/// Evaluates a polynomial at the `self` point value, using [Horner's method].
///
/// [Horner's method]: https://en.wikipedia.org/wiki/Horner%27s_method#Polynomial_evaluation_and_long_division
#[must_use]
fn eval_poly(self, coefficients: &[Self]) -> Self;
/// Approximates the derivative of the 1D function `f` at `x` point using step size `h`.
///
/// Uses the [finite difference method].
///
/// See also the [`autodiff`] attr macro, enabled with the `nightly_autodiff` feature.
///
/// [finite difference method]: https://en.wikipedia.org/wiki/Finite_difference_method
fn derivative<F>(f: F, x: Self, h: Self) -> Self
where
F: Fn(Self) -> Self;
/// Approximates the integral of the 1D function `f` over the range `[x, y]`
/// using `n` subdivisions.
///
/// Uses the [Riemann Sum](https://en.wikipedia.org/wiki/Riemann_sum).
fn integrate<F>(f: F, x: Self, y: Self, n: usize) -> Self
where
F: Fn(Self) -> Self;
/// Approximates the partial derivative of the 2D function `f` at point (`x`, `y`)
/// with step size `h`, differentiating over `x`.
fn partial_derivative_x<F>(f: F, x: Self, y: Self, h: Self) -> Self
where
F: Fn(Self, Self) -> Self;
/// Approximates the partial derivative of the 2D function `f` at point (`x`, `y`)
/// with step size `h`, differentiating over `x`.
fn partial_derivative_y<F>(f: F, x: Self, y: Self, h: Self) -> Self
where
F: Fn(Self, Self) -> Self;
}
macro_rules! impl_float_ext {
() => {
impl_float_ext![
(f32, u32 | i32):"_float_f32":"_cmp_f32",
(f64, u32 | i32):"_float_f64":"_cmp_f32"];
};
// $f: the floating-point type.
// $ue: unsigned int type with the same bit-size.
// $ie: the integer type for integer exponentiation.
// $cap: the capability feature that enables the given implementation. E.g "_float_f32".
// $cmp: the feature that enables the given implementation. E.g "_cmp_f32".
($( ($f:ty, $ue:ty|$ie:ty): $cap:literal : $cmp:literal ),+) => {
$( impl_float_ext![@$f, $ue|$ie, $cap:$cmp]; )+
};
(@$f:ty, $ue:ty|$ie:ty, $cap:literal : $cmp:literal) => {
#[cfg(feature = $cap )]
#[cfg_attr(feature = "nightly_doc", doc(cfg(feature = $cap)))]
impl ExtFloat for $f {
fn floor(self) -> Self { Float(self).floor().0 }
fn ceil(self) -> Self { Float(self).ceil().0 }
fn round(self) -> Self { Float(self).round_ties_away().0 }
fn round_ties_away(self) -> Self { Float(self).round_ties_away().0 }
fn round_ties_even(self) -> Self { Float(self).round_ties_even().0 }
fn round_ties_odd(self) -> Self { Float(self).round_ties_odd().0 }
fn trunc(self) -> Self { Float(self).trunc().0 }
fn fract(self) -> Self { Float(self).fract().0 }
fn split(self) -> (Self, Self) { let (i, f) = Float(self).split(); (i.0, f.0) }
fn abs(self) -> Self { Float(self).abs().0 }
fn neg_abs(self) -> Self { Float(self).neg_abs().0 }
fn sign(self) -> Sign { Float(self).sign() }
fn sign_nonzero(self) -> Sign { Float(self).sign_nonzero() }
fn signum(self) -> Self { Float(self).signum().0 }
fn flip_sign(self) -> Self { Float(self).flip_sign().0 }
fn is_sign_positive(self) -> bool { Float(self).is_sign_positive() }
fn is_sign_negative(self) -> bool { Float(self).is_sign_negative() }
fn is_zero(self) -> bool { Float(self).is_zero() }
fn is_sign_positive_nonzero(self) -> bool {
Float(self).is_sign_positive_nonzero() }
fn is_sign_negative_nonzero(self) -> bool {
Float(self).is_sign_negative_nonzero() }
fn copysign(self, sign: Self) -> Self { Float(self).copysign(sign).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn mul_add(self, mul: Self, add: Self) -> Self {
Float(self).mul_add(mul, add).0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn mul_add(self, mul: Self, add: Self) -> Self {
Float(self).mul_add_fallback(mul, add).0
}
fn div_euclid(self, rhs: Self) -> Self { Float(self).div_euclid(rhs).0 }
fn rem_euclid(self, rhs: Self) -> Self { Float(self).rem_euclid(rhs).0 }
fn scale(self, min: Self, max: Self, u: Self, v: Self) -> Self {
Float(self).scale(min, max, u, v).0 }
fn lerp(self, u: Self, v: Self) -> Self { Float(self).lerp(u, v).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn powf(self, y: Self) -> Self { Float(self).powf(y).0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn powf(self, y: Self) -> Self {
Float(self).powf_series(y, Float(self).ln_series_terms()).0
}
fn powi(self, p: $ie) -> Self { Float(self).powi(p).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn sqrt(self) -> Self { Float(self).sqrt().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn sqrt(self) -> Self { Float(self).sqrt_nr().0 }
fn sqrt_fisr(self) -> Self { Float(self).sqrt_fisr().0 }
fn fisr(self) -> Self { Float(self).fisr().0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn cbrt(self) -> Self { Float(self).cbrt().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn cbrt(self) -> Self { Float(self).cbrt_nr().0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn hypot(self, rhs: Self) -> Self { Float(self).hypot(rhs).0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn hypot(self, rhs: Self) -> Self { Float(self).hypot_nr(rhs).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn exp(self) -> Self { Float(self).exp().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn exp(self) -> Self {
Float(self).exp_series(Float(self).exp_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn exp2(self) -> Self { Float(self).exp2().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn exp2(self) -> Self {
Float(self).exp2_series(Float(self).exp2_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn exp_m1(self) -> Self { Float(self).exp_m1().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn exp_m1(self) -> Self {
Float(self).exp_m1_series(Float(self).exp_series_terms()).0
}
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn ln(self) -> Self { Float(self).ln().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn ln(self) -> Self {
Float(self).ln_series(Float(self).ln_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn ln_1p(self) -> Self { Float(self).ln_1p().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn ln_1p(self) -> Self {
Float(self).ln_1p_series(Float(self).ln_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn log(self, base: Self) -> Self { Float(self).log(base).0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn log(self, base: Self) -> Self {
Float(self).log_series(base, Float(self).ln_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn log2(self) -> Self { Float(self).log2().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn log2(self) -> Self {
Float(self).log2_series(Float(self).ln_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn log10(self) -> Self { Float(self).log10().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn log10(self) -> Self {
Float(self).log10_series(Float(self).ln_series_terms()).0 }
fn factorial(a: $ue) -> Self { Float::<Self>::factorial(a).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn sin(self) -> Self { Float(self).sin().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn sin(self) -> Self { Float(self).sin_series(8).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn cos(self) -> Self { Float(self).cos().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn cos(self) -> Self { Float(self).cos_series(8).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn sin_cos(self) -> (Self, Self) { let (s, c) = Float(self).sin_cos(); (s.0, c.0) }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn sin_cos(self) -> (Self, Self) {
let (s, c) = Float(self).sin_cos_series(8); (s.0, c.0) }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn tan(self) -> Self { Float(self).tan().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn tan(self) -> Self { Float(self).tan_series(8).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn asin(self) -> Self { Float(self).asin().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn asin(self) -> Self {
Float(self).asin_series(Float(self).asin_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn acos(self) -> Self { Float(self).acos().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn acos(self) -> Self {
Float(self).acos_series(Float(self).acos_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn atan(self) -> Self { Float(self).atan().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn atan(self) -> Self {
Float(self).atan_series(Float(self).atan_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn atan2(self, other: Self) -> Self { Float(self).atan2(other).0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn atan2(self, other: Self) -> Self {
Float(self).atan2_series(other, Float(self).atan_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn sinh(self) -> Self { Float(self).sinh().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn sinh(self) -> Self {
Float(self).sinh_series(Float(self).exp_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn cosh(self) -> Self { Float(self).cosh().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn cosh(self) -> Self {
Float(self).cosh_series(Float(self).exp_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn tanh(self) -> Self { Float(self).tanh().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn tanh(self) -> Self {
Float(self).tanh_series(Float(self).exp_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn asinh(self) -> Self { Float(self).asinh().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn asinh(self) -> Self {
Float(self).asinh_series(Float(self).exp_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn acosh(self) -> Self { Float(self).acosh().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn acosh(self) -> Self {
Float(self).acosh_series(Float(self).exp_series_terms()).0 }
#[cfg(any(feature = "std", feature = "dep_libm"))]
fn atanh(self) -> Self { Float(self).atanh().0 }
#[cfg(not(any(feature = "std", feature = "dep_libm")))]
fn atanh(self) -> Self {
Float(self).atanh_series(Float(self).exp_series_terms()).0 }
fn clamp_nan(self, min: Self, max: Self) -> Self { Float(self).clamp_nan(min, max).0 }
fn max_nan(self, other: Self) -> Self { Float(self).max_nan(other).0 }
fn min_nan(self, other: Self) -> Self { Float(self).min_nan(other).0 }
#[cfg(feature = $cmp)]
fn clamp_total(self, min: Self, max: Self) -> Self {
Float(self).clamp_total(min, max).0
}
#[cfg(not(feature = $cmp))]
fn clamp_total(self, _: Self, _: Self) -> Self { <$f>::NAN }
#[cfg(feature = $cmp)]
fn max_total(self, other: Self) -> Self { Float(self).max_total(other).0 }
#[cfg(not(feature = $cmp))]
fn max_total(self, _: Self) -> Self { <$f>::NAN }
#[cfg(feature = $cmp)]
fn min_total(self, other: Self) -> Self { Float(self).min_total(other).0 }
#[cfg(not(feature = $cmp))]
fn min_total(self, _: Self) -> Self { <$f>::NAN }
fn eval_poly(self, coefficients: &[Self]) -> Self {
Float(self).eval_poly(coefficients).0
}
fn derivative<F>(f: F, x: Self, h: Self) -> Self
where F: Fn(Self) -> Self {
Float::<Self>::derivative(f, x, h).0
}
fn integrate<F>(f: F, x: Self, y: Self, n: usize) -> Self
where F: Fn(Self) -> Self {
Float::<Self>::integrate(f, x, y, n).0
}
fn partial_derivative_x<F>(f: F, x: Self, y: Self, h: Self) -> Self
where
F: Fn(Self, Self) -> Self,
{
Float::<Self>::partial_derivative_x(f, x, y, h).0
}
fn partial_derivative_y<F>(f: F, x: Self, y: Self, h: Self) -> Self
where
F: Fn(Self, Self) -> Self,
{
Float::<Self>::partial_derivative_y(f, x, y, h).0
}
}
}
}
impl_float_ext!();