|
11 | 11 | //! Operations and constants for `f32` |
12 | 12 |
|
13 | 13 | use from_str; |
14 | | -use libc::c_int; |
15 | 14 | use num::{Zero, One, strconv}; |
16 | 15 | use prelude::*; |
17 | 16 |
|
@@ -102,8 +101,8 @@ delegate!( |
102 | 101 | fn sinh(n: c_float) -> c_float = c_float_utils::sinh, |
103 | 102 | fn tan(n: c_float) -> c_float = c_float_utils::tan, |
104 | 103 | fn tanh(n: c_float) -> c_float = c_float_utils::tanh, |
105 | | - fn tgamma(n: c_float) -> c_float = c_float_utils::tgamma) |
106 | | - |
| 104 | + fn tgamma(n: c_float) -> c_float = c_float_utils::tgamma |
| 105 | +) |
107 | 106 |
|
108 | 107 | // These are not defined inside consts:: for consistency with |
109 | 108 | // the integer types |
@@ -368,154 +367,153 @@ impl Fractional for f32 { |
368 | 367 | fn recip(&self) -> f32 { 1.0 / *self } |
369 | 368 | } |
370 | 369 |
|
371 | | -impl Real for f32 { |
372 | | - /// Archimedes' constant |
| 370 | +impl Algebraic for f32 { |
373 | 371 | #[inline(always)] |
374 | | - fn pi() -> f32 { 3.14159265358979323846264338327950288 } |
375 | | - |
376 | | - /// 2.0 * pi |
377 | | - #[inline(always)] |
378 | | - fn two_pi() -> f32 { 6.28318530717958647692528676655900576 } |
379 | | - |
380 | | - /// pi / 2.0 |
381 | | - #[inline(always)] |
382 | | - fn frac_pi_2() -> f32 { 1.57079632679489661923132169163975144 } |
383 | | - |
384 | | - /// pi / 3.0 |
385 | | - #[inline(always)] |
386 | | - fn frac_pi_3() -> f32 { 1.04719755119659774615421446109316763 } |
| 372 | + fn pow(&self, n: f32) -> f32 { pow(*self, n) } |
387 | 373 |
|
388 | | - /// pi / 4.0 |
389 | 374 | #[inline(always)] |
390 | | - fn frac_pi_4() -> f32 { 0.785398163397448309615660845819875721 } |
| 375 | + fn sqrt(&self) -> f32 { sqrt(*self) } |
391 | 376 |
|
392 | | - /// pi / 6.0 |
393 | 377 | #[inline(always)] |
394 | | - fn frac_pi_6() -> f32 { 0.52359877559829887307710723054658381 } |
| 378 | + fn rsqrt(&self) -> f32 { self.sqrt().recip() } |
395 | 379 |
|
396 | | - /// pi / 8.0 |
397 | 380 | #[inline(always)] |
398 | | - fn frac_pi_8() -> f32 { 0.39269908169872415480783042290993786 } |
| 381 | + fn cbrt(&self) -> f32 { cbrt(*self) } |
399 | 382 |
|
400 | | - /// 1 .0/ pi |
401 | 383 | #[inline(always)] |
402 | | - fn frac_1_pi() -> f32 { 0.318309886183790671537767526745028724 } |
| 384 | + fn hypot(&self, other: f32) -> f32 { hypot(*self, other) } |
| 385 | +} |
403 | 386 |
|
404 | | - /// 2.0 / pi |
| 387 | +impl Trigonometric for f32 { |
405 | 388 | #[inline(always)] |
406 | | - fn frac_2_pi() -> f32 { 0.636619772367581343075535053490057448 } |
| 389 | + fn sin(&self) -> f32 { sin(*self) } |
407 | 390 |
|
408 | | - /// 2.0 / sqrt(pi) |
409 | 391 | #[inline(always)] |
410 | | - fn frac_2_sqrtpi() -> f32 { 1.12837916709551257389615890312154517 } |
| 392 | + fn cos(&self) -> f32 { cos(*self) } |
411 | 393 |
|
412 | | - /// sqrt(2.0) |
413 | 394 | #[inline(always)] |
414 | | - fn sqrt2() -> f32 { 1.41421356237309504880168872420969808 } |
| 395 | + fn tan(&self) -> f32 { tan(*self) } |
415 | 396 |
|
416 | | - /// 1.0 / sqrt(2.0) |
417 | 397 | #[inline(always)] |
418 | | - fn frac_1_sqrt2() -> f32 { 0.707106781186547524400844362104849039 } |
| 398 | + fn asin(&self) -> f32 { asin(*self) } |
419 | 399 |
|
420 | | - /// Euler's number |
421 | 400 | #[inline(always)] |
422 | | - fn e() -> f32 { 2.71828182845904523536028747135266250 } |
| 401 | + fn acos(&self) -> f32 { acos(*self) } |
423 | 402 |
|
424 | | - /// log2(e) |
425 | 403 | #[inline(always)] |
426 | | - fn log2_e() -> f32 { 1.44269504088896340735992468100189214 } |
| 404 | + fn atan(&self) -> f32 { atan(*self) } |
427 | 405 |
|
428 | | - /// log10(e) |
429 | 406 | #[inline(always)] |
430 | | - fn log10_e() -> f32 { 0.434294481903251827651128918916605082 } |
| 407 | + fn atan2(&self, other: f32) -> f32 { atan2(*self, other) } |
| 408 | +} |
431 | 409 |
|
432 | | - /// log(2.0) |
| 410 | +impl Exponential for f32 { |
433 | 411 | #[inline(always)] |
434 | | - fn log_2() -> f32 { 0.693147180559945309417232121458176568 } |
| 412 | + fn exp(&self) -> f32 { exp(*self) } |
435 | 413 |
|
436 | | - /// log(10.0) |
437 | 414 | #[inline(always)] |
438 | | - fn log_10() -> f32 { 2.30258509299404568401799145468436421 } |
| 415 | + fn exp2(&self) -> f32 { exp2(*self) } |
439 | 416 |
|
440 | 417 | #[inline(always)] |
441 | | - fn pow(&self, n: f32) -> f32 { pow(*self, n) } |
| 418 | + fn expm1(&self) -> f32 { expm1(*self) } |
442 | 419 |
|
443 | 420 | #[inline(always)] |
444 | | - fn exp(&self) -> f32 { exp(*self) } |
| 421 | + fn log(&self) -> f32 { ln(*self) } |
445 | 422 |
|
446 | 423 | #[inline(always)] |
447 | | - fn exp2(&self) -> f32 { exp2(*self) } |
| 424 | + fn log2(&self) -> f32 { log2(*self) } |
448 | 425 |
|
449 | 426 | #[inline(always)] |
450 | | - fn expm1(&self) -> f32 { expm1(*self) } |
| 427 | + fn log10(&self) -> f32 { log10(*self) } |
| 428 | +} |
451 | 429 |
|
| 430 | +impl Hyperbolic for f32 { |
452 | 431 | #[inline(always)] |
453 | | - fn ldexp(&self, n: int) -> f32 { ldexp(*self, n as c_int) } |
| 432 | + fn sinh(&self) -> f32 { sinh(*self) } |
454 | 433 |
|
455 | 434 | #[inline(always)] |
456 | | - fn log(&self) -> f32 { ln(*self) } |
| 435 | + fn cosh(&self) -> f32 { cosh(*self) } |
457 | 436 |
|
458 | 437 | #[inline(always)] |
459 | | - fn log2(&self) -> f32 { log2(*self) } |
| 438 | + fn tanh(&self) -> f32 { tanh(*self) } |
| 439 | +} |
460 | 440 |
|
| 441 | +impl Real for f32 { |
| 442 | + /// Archimedes' constant |
461 | 443 | #[inline(always)] |
462 | | - fn log10(&self) -> f32 { log10(*self) } |
| 444 | + fn pi() -> f32 { 3.14159265358979323846264338327950288 } |
463 | 445 |
|
| 446 | + /// 2.0 * pi |
464 | 447 | #[inline(always)] |
465 | | - fn log_radix(&self) -> f32 { log_radix(*self) as f32 } |
| 448 | + fn two_pi() -> f32 { 6.28318530717958647692528676655900576 } |
466 | 449 |
|
| 450 | + /// pi / 2.0 |
467 | 451 | #[inline(always)] |
468 | | - fn ilog_radix(&self) -> int { ilog_radix(*self) as int } |
| 452 | + fn frac_pi_2() -> f32 { 1.57079632679489661923132169163975144 } |
469 | 453 |
|
| 454 | + /// pi / 3.0 |
470 | 455 | #[inline(always)] |
471 | | - fn sqrt(&self) -> f32 { sqrt(*self) } |
| 456 | + fn frac_pi_3() -> f32 { 1.04719755119659774615421446109316763 } |
472 | 457 |
|
| 458 | + /// pi / 4.0 |
473 | 459 | #[inline(always)] |
474 | | - fn rsqrt(&self) -> f32 { self.sqrt().recip() } |
| 460 | + fn frac_pi_4() -> f32 { 0.785398163397448309615660845819875721 } |
475 | 461 |
|
| 462 | + /// pi / 6.0 |
476 | 463 | #[inline(always)] |
477 | | - fn cbrt(&self) -> f32 { cbrt(*self) } |
| 464 | + fn frac_pi_6() -> f32 { 0.52359877559829887307710723054658381 } |
478 | 465 |
|
479 | | - /// Converts to degrees, assuming the number is in radians |
| 466 | + /// pi / 8.0 |
480 | 467 | #[inline(always)] |
481 | | - fn to_degrees(&self) -> f32 { *self * (180.0 / Real::pi::<f32>()) } |
| 468 | + fn frac_pi_8() -> f32 { 0.39269908169872415480783042290993786 } |
482 | 469 |
|
483 | | - /// Converts to radians, assuming the number is in degrees |
| 470 | + /// 1 .0/ pi |
484 | 471 | #[inline(always)] |
485 | | - fn to_radians(&self) -> f32 { *self * (Real::pi::<f32>() / 180.0) } |
| 472 | + fn frac_1_pi() -> f32 { 0.318309886183790671537767526745028724 } |
486 | 473 |
|
| 474 | + /// 2.0 / pi |
487 | 475 | #[inline(always)] |
488 | | - fn hypot(&self, other: f32) -> f32 { hypot(*self, other) } |
| 476 | + fn frac_2_pi() -> f32 { 0.636619772367581343075535053490057448 } |
489 | 477 |
|
| 478 | + /// 2.0 / sqrt(pi) |
490 | 479 | #[inline(always)] |
491 | | - fn sin(&self) -> f32 { sin(*self) } |
| 480 | + fn frac_2_sqrtpi() -> f32 { 1.12837916709551257389615890312154517 } |
492 | 481 |
|
| 482 | + /// sqrt(2.0) |
493 | 483 | #[inline(always)] |
494 | | - fn cos(&self) -> f32 { cos(*self) } |
| 484 | + fn sqrt2() -> f32 { 1.41421356237309504880168872420969808 } |
495 | 485 |
|
| 486 | + /// 1.0 / sqrt(2.0) |
496 | 487 | #[inline(always)] |
497 | | - fn tan(&self) -> f32 { tan(*self) } |
| 488 | + fn frac_1_sqrt2() -> f32 { 0.707106781186547524400844362104849039 } |
498 | 489 |
|
| 490 | + /// Euler's number |
499 | 491 | #[inline(always)] |
500 | | - fn asin(&self) -> f32 { asin(*self) } |
| 492 | + fn e() -> f32 { 2.71828182845904523536028747135266250 } |
501 | 493 |
|
| 494 | + /// log2(e) |
502 | 495 | #[inline(always)] |
503 | | - fn acos(&self) -> f32 { acos(*self) } |
| 496 | + fn log2_e() -> f32 { 1.44269504088896340735992468100189214 } |
504 | 497 |
|
| 498 | + /// log10(e) |
505 | 499 | #[inline(always)] |
506 | | - fn atan(&self) -> f32 { atan(*self) } |
| 500 | + fn log10_e() -> f32 { 0.434294481903251827651128918916605082 } |
507 | 501 |
|
| 502 | + /// log(2.0) |
508 | 503 | #[inline(always)] |
509 | | - fn atan2(&self, other: f32) -> f32 { atan2(*self, other) } |
| 504 | + fn log_2() -> f32 { 0.693147180559945309417232121458176568 } |
510 | 505 |
|
| 506 | + /// log(10.0) |
511 | 507 | #[inline(always)] |
512 | | - fn sinh(&self) -> f32 { sinh(*self) } |
| 508 | + fn log_10() -> f32 { 2.30258509299404568401799145468436421 } |
513 | 509 |
|
| 510 | + /// Converts to degrees, assuming the number is in radians |
514 | 511 | #[inline(always)] |
515 | | - fn cosh(&self) -> f32 { cosh(*self) } |
| 512 | + fn to_degrees(&self) -> f32 { *self * (180.0 / Real::pi::<f32>()) } |
516 | 513 |
|
| 514 | + /// Converts to radians, assuming the number is in degrees |
517 | 515 | #[inline(always)] |
518 | | - fn tanh(&self) -> f32 { tanh(*self) } |
| 516 | + fn to_radians(&self) -> f32 { *self * (Real::pi::<f32>() / 180.0) } |
519 | 517 | } |
520 | 518 |
|
521 | 519 | impl Bounded for f32 { |
|
0 commit comments