@@ -218,8 +218,9 @@ impl Signed for f32 {
218
218
unsafe { intrinsics:: fabsf32 ( * self ) }
219
219
}
220
220
221
- /// The positive difference of two numbers. Returns `0.0` if the number is less than or
222
- /// equal to `other`, otherwise the difference between`self` and `other` is returned.
221
+ /// The positive difference of two numbers. Returns `0.0` if the number is
222
+ /// less than or equal to `other`, otherwise the difference between`self`
223
+ /// and `other` is returned.
223
224
#[ inline]
224
225
fn abs_sub ( & self , other : & f32 ) -> f32 {
225
226
unsafe { cmath:: fdimf ( * self , * other) }
@@ -257,20 +258,6 @@ impl Bounded for f32 {
257
258
impl Primitive for f32 { }
258
259
259
260
impl Float for f32 {
260
- fn powi ( self , n : i32 ) -> f32 {
261
- unsafe { intrinsics:: powif32 ( self , n) }
262
- }
263
-
264
- #[ inline]
265
- fn max ( self , other : f32 ) -> f32 {
266
- unsafe { cmath:: fmaxf ( self , other) }
267
- }
268
-
269
- #[ inline]
270
- fn min ( self , other : f32 ) -> f32 {
271
- unsafe { cmath:: fminf ( self , other) }
272
- }
273
-
274
261
#[ inline]
275
262
fn nan ( ) -> f32 { 0.0 / 0.0 }
276
263
@@ -305,8 +292,9 @@ impl Float for f32 {
305
292
self . classify ( ) == FPNormal
306
293
}
307
294
308
- /// Returns the floating point category of the number. If only one property is going to
309
- /// be tested, it is generally faster to use the specific predicate instead.
295
+ /// Returns the floating point category of the number. If only one property
296
+ /// is going to be tested, it is generally faster to use the specific
297
+ /// predicate instead.
310
298
fn classify ( self ) -> FPCategory {
311
299
static EXP_MASK : u32 = 0x7f800000 ;
312
300
static MAN_MASK : u32 = 0x007fffff ;
@@ -342,13 +330,15 @@ impl Float for f32 {
342
330
#[ inline]
343
331
fn max_10_exp ( _: Option < f32 > ) -> int { 38 }
344
332
345
- /// Constructs a floating point number by multiplying `x` by 2 raised to the power of `exp`
333
+ /// Constructs a floating point number by multiplying `x` by 2 raised to the
334
+ /// power of `exp`
346
335
#[ inline]
347
336
fn ldexp ( x : f32 , exp : int ) -> f32 {
348
337
unsafe { cmath:: ldexpf ( x, exp as c_int ) }
349
338
}
350
339
351
- /// Breaks the number into a normalized fraction and a base-2 exponent, satisfying:
340
+ /// Breaks the number into a normalized fraction and a base-2 exponent,
341
+ /// satisfying:
352
342
///
353
343
/// - `self = x * pow(2, exp)`
354
344
/// - `0.5 <= abs(x) < 1.0`
@@ -361,34 +351,6 @@ impl Float for f32 {
361
351
}
362
352
}
363
353
364
- /// Returns the exponential of the number, minus `1`, in a way that is accurate
365
- /// even if the number is close to zero
366
- #[ inline]
367
- fn exp_m1 ( self ) -> f32 {
368
- unsafe { cmath:: expm1f ( self ) }
369
- }
370
-
371
- /// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
372
- /// than if the operations were performed separately
373
- #[ inline]
374
- fn ln_1p ( self ) -> f32 {
375
- unsafe { cmath:: log1pf ( self ) }
376
- }
377
-
378
- /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
379
- /// produces a more accurate result with better performance than a separate multiplication
380
- /// operation followed by an add.
381
- #[ inline]
382
- fn mul_add ( self , a : f32 , b : f32 ) -> f32 {
383
- unsafe { intrinsics:: fmaf32 ( self , a, b) }
384
- }
385
-
386
- /// Returns the next representable floating-point value in the direction of `other`
387
- #[ inline]
388
- fn next_after ( self , other : f32 ) -> f32 {
389
- unsafe { cmath:: nextafterf ( self , other) }
390
- }
391
-
392
354
/// Returns the mantissa, exponent and sign as integers.
393
355
fn integer_decode ( self ) -> ( u64 , i16 , i8 ) {
394
356
let bits: u32 = unsafe { cast:: transmute ( self ) } ;
@@ -404,6 +366,13 @@ impl Float for f32 {
404
366
( mantissa as u64 , exponent, sign)
405
367
}
406
368
369
+ /// Returns the next representable floating-point value in the direction of
370
+ /// `other`.
371
+ #[ inline]
372
+ fn next_after ( self , other : f32 ) -> f32 {
373
+ unsafe { cmath:: nextafterf ( self , other) }
374
+ }
375
+
407
376
/// Round half-way cases toward `NEG_INFINITY`
408
377
#[ inline]
409
378
fn floor ( self ) -> f32 {
@@ -437,100 +406,102 @@ impl Float for f32 {
437
406
#[ inline]
438
407
fn fract ( self ) -> f32 { self - self . trunc ( ) }
439
408
440
- /// Archimedes' constant
441
- #[ inline]
442
- fn pi ( ) -> f32 { 3.14159265358979323846264338327950288 }
443
-
444
- /// 2.0 * pi
445
409
#[ inline]
446
- fn two_pi ( ) -> f32 { 6.28318530717958647692528676655900576 }
410
+ fn max ( self , other : f32 ) -> f32 {
411
+ unsafe { cmath:: fmaxf ( self , other) }
412
+ }
447
413
448
- /// pi / 2.0
449
414
#[ inline]
450
- fn frac_pi_2 ( ) -> f32 { 1.57079632679489661923132169163975144 }
415
+ fn min ( self , other : f32 ) -> f32 {
416
+ unsafe { cmath:: fminf ( self , other) }
417
+ }
451
418
452
- /// pi / 3.0
419
+ /// Fused multiply-add. Computes `(self * a) + b` with only one rounding
420
+ /// error. This produces a more accurate result with better performance than
421
+ /// a separate multiplication operation followed by an add.
453
422
#[ inline]
454
- fn frac_pi_3 ( ) -> f32 { 1.04719755119659774615421446109316763 }
423
+ fn mul_add ( self , a : f32 , b : f32 ) -> f32 {
424
+ unsafe { intrinsics:: fmaf32 ( self , a, b) }
425
+ }
455
426
456
- /// pi / 4.0
427
+ /// The reciprocal (multiplicative inverse) of the number
457
428
#[ inline]
458
- fn frac_pi_4 ( ) -> f32 { 0.785398163397448309615660845819875721 }
429
+ fn recip ( self ) -> f32 { 1.0 / self }
459
430
460
- /// pi / 6.0
461
- # [ inline ]
462
- fn frac_pi_6 ( ) -> f32 { 0.52359877559829887307710723054658381 }
431
+ fn powi ( self , n : i32 ) -> f32 {
432
+ unsafe { intrinsics :: powif32 ( self , n ) }
433
+ }
463
434
464
- /// pi / 8.0
465
435
#[ inline]
466
- fn frac_pi_8 ( ) -> f32 { 0.39269908169872415480783042290993786 }
436
+ fn powf ( self , n : f32 ) -> f32 {
437
+ unsafe { intrinsics:: powf32 ( self , n) }
438
+ }
467
439
468
- /// 1 .0/ pi
440
+ /// sqrt(2.0)
469
441
#[ inline]
470
- fn frac_1_pi ( ) -> f32 { 0.318309886183790671537767526745028724 }
442
+ fn sqrt2 ( ) -> f32 { 1.41421356237309504880168872420969808 }
471
443
472
- /// 2 .0 / pi
444
+ /// 1 .0 / sqrt(2.0)
473
445
#[ inline]
474
- fn frac_2_pi ( ) -> f32 { 0.636619772367581343075535053490057448 }
446
+ fn frac_1_sqrt2 ( ) -> f32 { 0.707106781186547524400844362104849039 }
475
447
476
- /// 2.0 / sqrt(pi)
477
448
#[ inline]
478
- fn frac_2_sqrtpi ( ) -> f32 { 1.12837916709551257389615890312154517 }
449
+ fn sqrt ( self ) -> f32 {
450
+ unsafe { intrinsics:: sqrtf32 ( self ) }
451
+ }
479
452
480
- /// sqrt(2.0)
481
453
#[ inline]
482
- fn sqrt2 ( ) -> f32 { 1.41421356237309504880168872420969808 }
454
+ fn rsqrt ( self ) -> f32 { self . sqrt ( ) . recip ( ) }
483
455
484
- /// 1.0 / sqrt(2.0)
485
456
#[ inline]
486
- fn frac_1_sqrt2 ( ) -> f32 { 0.707106781186547524400844362104849039 }
457
+ fn cbrt ( self ) -> f32 {
458
+ unsafe { cmath:: cbrtf ( self ) }
459
+ }
487
460
488
- /// Euler's number
489
461
#[ inline]
490
- fn e ( ) -> f32 { 2.71828182845904523536028747135266250 }
462
+ fn hypot ( self , other : f32 ) -> f32 {
463
+ unsafe { cmath:: hypotf ( self , other) }
464
+ }
491
465
492
- /// log2(e)
466
+ /// Archimedes' constant
493
467
#[ inline]
494
- fn log2_e ( ) -> f32 { 1.44269504088896340735992468100189214 }
468
+ fn pi ( ) -> f32 { 3.14159265358979323846264338327950288 }
495
469
496
- /// log10(e)
470
+ /// 2.0 * pi
497
471
#[ inline]
498
- fn log10_e ( ) -> f32 { 0.434294481903251827651128918916605082 }
472
+ fn two_pi ( ) -> f32 { 6.28318530717958647692528676655900576 }
499
473
500
- /// ln( 2.0)
474
+ /// pi / 2.0
501
475
#[ inline]
502
- fn ln_2 ( ) -> f32 { 0.693147180559945309417232121458176568 }
476
+ fn frac_pi_2 ( ) -> f32 { 1.57079632679489661923132169163975144 }
503
477
504
- /// ln(10.0)
478
+ /// pi / 3.0
505
479
#[ inline]
506
- fn ln_10 ( ) -> f32 { 2.30258509299404568401799145468436421 }
480
+ fn frac_pi_3 ( ) -> f32 { 1.04719755119659774615421446109316763 }
507
481
508
- /// The reciprocal (multiplicative inverse) of the number
482
+ /// pi / 4.0
509
483
#[ inline]
510
- fn recip ( self ) -> f32 { 1.0 / self }
484
+ fn frac_pi_4 ( ) -> f32 { 0.785398163397448309615660845819875721 }
511
485
486
+ /// pi / 6.0
512
487
#[ inline]
513
- fn powf ( self , n : f32 ) -> f32 {
514
- unsafe { intrinsics:: powf32 ( self , n) }
515
- }
488
+ fn frac_pi_6 ( ) -> f32 { 0.52359877559829887307710723054658381 }
516
489
490
+ /// pi / 8.0
517
491
#[ inline]
518
- fn sqrt ( self ) -> f32 {
519
- unsafe { intrinsics:: sqrtf32 ( self ) }
520
- }
492
+ fn frac_pi_8 ( ) -> f32 { 0.39269908169872415480783042290993786 }
521
493
494
+ /// 1 .0/ pi
522
495
#[ inline]
523
- fn rsqrt ( self ) -> f32 { self . sqrt ( ) . recip ( ) }
496
+ fn frac_1_pi ( ) -> f32 { 0.318309886183790671537767526745028724 }
524
497
498
+ /// 2.0 / pi
525
499
#[ inline]
526
- fn cbrt ( self ) -> f32 {
527
- unsafe { cmath:: cbrtf ( self ) }
528
- }
500
+ fn frac_2_pi ( ) -> f32 { 0.636619772367581343075535053490057448 }
529
501
502
+ /// 2.0 / sqrt(pi)
530
503
#[ inline]
531
- fn hypot ( self , other : f32 ) -> f32 {
532
- unsafe { cmath:: hypotf ( self , other) }
533
- }
504
+ fn frac_2_sqrtpi ( ) -> f32 { 1.12837916709551257389615890312154517 }
534
505
535
506
#[ inline]
536
507
fn sin ( self ) -> f32 {
@@ -573,6 +544,26 @@ impl Float for f32 {
573
544
( self . sin ( ) , self . cos ( ) )
574
545
}
575
546
547
+ /// Euler's number
548
+ #[ inline]
549
+ fn e ( ) -> f32 { 2.71828182845904523536028747135266250 }
550
+
551
+ /// log2(e)
552
+ #[ inline]
553
+ fn log2_e ( ) -> f32 { 1.44269504088896340735992468100189214 }
554
+
555
+ /// log10(e)
556
+ #[ inline]
557
+ fn log10_e ( ) -> f32 { 0.434294481903251827651128918916605082 }
558
+
559
+ /// ln(2.0)
560
+ #[ inline]
561
+ fn ln_2 ( ) -> f32 { 0.693147180559945309417232121458176568 }
562
+
563
+ /// ln(10.0)
564
+ #[ inline]
565
+ fn ln_10 ( ) -> f32 { 2.30258509299404568401799145468436421 }
566
+
576
567
/// Returns the exponential of the number
577
568
#[ inline]
578
569
fn exp ( self ) -> f32 {
@@ -585,6 +576,13 @@ impl Float for f32 {
585
576
unsafe { intrinsics:: exp2f32 ( self ) }
586
577
}
587
578
579
+ /// Returns the exponential of the number, minus `1`, in a way that is
580
+ /// accurate even if the number is close to zero
581
+ #[ inline]
582
+ fn exp_m1 ( self ) -> f32 {
583
+ unsafe { cmath:: expm1f ( self ) }
584
+ }
585
+
588
586
/// Returns the natural logarithm of the number
589
587
#[ inline]
590
588
fn ln ( self ) -> f32 {
@@ -607,6 +605,13 @@ impl Float for f32 {
607
605
unsafe { intrinsics:: log10f32 ( self ) }
608
606
}
609
607
608
+ /// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more
609
+ /// accurately than if the operations were performed separately
610
+ #[ inline]
611
+ fn ln_1p ( self ) -> f32 {
612
+ unsafe { cmath:: log1pf ( self ) }
613
+ }
614
+
610
615
#[ inline]
611
616
fn sinh ( self ) -> f32 {
612
617
unsafe { cmath:: sinhf ( self ) }
0 commit comments