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