Skip to content

Commit 42450ef

Browse files
committed
Fix formatting in float implementations
1 parent bed70a4 commit 42450ef

File tree

2 files changed

+198
-72
lines changed

2 files changed

+198
-72
lines changed

src/libstd/num/f32.rs

+99-36
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use prelude::*;
1616

17+
use cast;
1718
use default::Default;
1819
use from_str::FromStr;
1920
use libc::{c_int};
@@ -213,12 +214,16 @@ impl Neg<f32> for f32 {
213214
impl Signed for f32 {
214215
/// Computes the absolute value. Returns `NAN` if the number is `NAN`.
215216
#[inline]
216-
fn abs(&self) -> f32 { unsafe{intrinsics::fabsf32(*self)} }
217+
fn abs(&self) -> f32 {
218+
unsafe { intrinsics::fabsf32(*self) }
219+
}
217220

218221
/// The positive difference of two numbers. Returns `0.0` if the number is less than or
219222
/// equal to `other`, otherwise the difference between`self` and `other` is returned.
220223
#[inline]
221-
fn abs_sub(&self, other: &f32) -> f32 { unsafe{cmath::fdimf(*self, *other)} }
224+
fn abs_sub(&self, other: &f32) -> f32 {
225+
unsafe { cmath::fdimf(*self, *other) }
226+
}
222227

223228
/// # Returns
224229
///
@@ -227,7 +232,9 @@ impl Signed for f32 {
227232
/// - `NAN` if the number is NaN
228233
#[inline]
229234
fn signum(&self) -> f32 {
230-
if self.is_nan() { NAN } else { unsafe{intrinsics::copysignf32(1.0, *self)} }
235+
if self.is_nan() { NAN } else {
236+
unsafe { intrinsics::copysignf32(1.0, *self) }
237+
}
231238
}
232239

233240
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
@@ -250,7 +257,9 @@ impl Bounded for f32 {
250257
impl Primitive for f32 {}
251258

252259
impl Float for f32 {
253-
fn powi(self, n: i32) -> f32 { unsafe{intrinsics::powif32(self, n)} }
260+
fn powi(self, n: i32) -> f32 {
261+
unsafe { intrinsics::powif32(self, n) }
262+
}
254263

255264
#[inline]
256265
fn max(self, other: f32) -> f32 {
@@ -302,7 +311,7 @@ impl Float for f32 {
302311
static EXP_MASK: u32 = 0x7f800000;
303312
static MAN_MASK: u32 = 0x007fffff;
304313

305-
let bits: u32 = unsafe {::cast::transmute(self)};
314+
let bits: u32 = unsafe { cast::transmute(self) };
306315
match (bits & MAN_MASK, bits & EXP_MASK) {
307316
(0, 0) => FPZero,
308317
(_, 0) => FPSubnormal,
@@ -335,7 +344,9 @@ impl Float for f32 {
335344

336345
/// Constructs a floating point number by multiplying `x` by 2 raised to the power of `exp`
337346
#[inline]
338-
fn ldexp(x: f32, exp: int) -> f32 { unsafe{cmath::ldexpf(x, exp as c_int)} }
347+
fn ldexp(x: f32, exp: int) -> f32 {
348+
unsafe { cmath::ldexpf(x, exp as c_int) }
349+
}
339350

340351
/// Breaks the number into a normalized fraction and a base-2 exponent, satisfying:
341352
///
@@ -353,28 +364,34 @@ impl Float for f32 {
353364
/// Returns the exponential of the number, minus `1`, in a way that is accurate
354365
/// even if the number is close to zero
355366
#[inline]
356-
fn exp_m1(self) -> f32 { unsafe{cmath::expm1f(self)} }
367+
fn exp_m1(self) -> f32 {
368+
unsafe { cmath::expm1f(self) }
369+
}
357370

358371
/// Returns the natural logarithm of the number plus `1` (`ln(1+n)`) more accurately
359372
/// than if the operations were performed separately
360373
#[inline]
361-
fn ln_1p(self) -> f32 { unsafe{cmath::log1pf(self)} }
374+
fn ln_1p(self) -> f32 {
375+
unsafe { cmath::log1pf(self) }
376+
}
362377

363378
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
364379
/// produces a more accurate result with better performance than a separate multiplication
365380
/// operation followed by an add.
366381
#[inline]
367-
fn mul_add(self, a: f32, b: f32) -> f32 { unsafe{intrinsics::fmaf32(self, a, b)} }
382+
fn mul_add(self, a: f32, b: f32) -> f32 {
383+
unsafe { intrinsics::fmaf32(self, a, b) }
384+
}
368385

369386
/// Returns the next representable floating-point value in the direction of `other`
370387
#[inline]
371-
fn next_after(self, other: f32) -> f32 { unsafe{cmath::nextafterf(self, other)} }
388+
fn next_after(self, other: f32) -> f32 {
389+
unsafe { cmath::nextafterf(self, other) }
390+
}
372391

373392
/// Returns the mantissa, exponent and sign as integers.
374393
fn integer_decode(self) -> (u64, i16, i8) {
375-
let bits: u32 = unsafe {
376-
::cast::transmute(self)
377-
};
394+
let bits: u32 = unsafe { cast::transmute(self) };
378395
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
379396
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
380397
let mantissa = if exponent == 0 {
@@ -389,19 +406,27 @@ impl Float for f32 {
389406

390407
/// Round half-way cases toward `NEG_INFINITY`
391408
#[inline]
392-
fn floor(self) -> f32 { unsafe{intrinsics::floorf32(self)} }
409+
fn floor(self) -> f32 {
410+
unsafe { intrinsics::floorf32(self) }
411+
}
393412

394413
/// Round half-way cases toward `INFINITY`
395414
#[inline]
396-
fn ceil(self) -> f32 { unsafe{intrinsics::ceilf32(self)} }
415+
fn ceil(self) -> f32 {
416+
unsafe { intrinsics::ceilf32(self) }
417+
}
397418

398419
/// Round half-way cases away from `0.0`
399420
#[inline]
400-
fn round(self) -> f32 { unsafe{intrinsics::roundf32(self)} }
421+
fn round(self) -> f32 {
422+
unsafe { intrinsics::roundf32(self) }
423+
}
401424

402425
/// The integer part of the number (rounds towards `0.0`)
403426
#[inline]
404-
fn trunc(self) -> f32 { unsafe{intrinsics::truncf32(self)} }
427+
fn trunc(self) -> f32 {
428+
unsafe { intrinsics::truncf32(self) }
429+
}
405430

406431
/// The fractional part of the number, satisfying:
407432
///
@@ -485,40 +510,62 @@ impl Float for f32 {
485510
fn recip(self) -> f32 { 1.0 / self }
486511

487512
#[inline]
488-
fn powf(self, n: f32) -> f32 { unsafe{intrinsics::powf32(self, n)} }
513+
fn powf(self, n: f32) -> f32 {
514+
unsafe { intrinsics::powf32(self, n) }
515+
}
489516

490517
#[inline]
491-
fn sqrt(self) -> f32 { unsafe{intrinsics::sqrtf32(self)} }
518+
fn sqrt(self) -> f32 {
519+
unsafe { intrinsics::sqrtf32(self) }
520+
}
492521

493522
#[inline]
494523
fn rsqrt(self) -> f32 { self.sqrt().recip() }
495524

496525
#[inline]
497-
fn cbrt(self) -> f32 { unsafe{cmath::cbrtf(self)} }
526+
fn cbrt(self) -> f32 {
527+
unsafe { cmath::cbrtf(self) }
528+
}
498529

499530
#[inline]
500-
fn hypot(self, other: f32) -> f32 { unsafe{cmath::hypotf(self, other)} }
531+
fn hypot(self, other: f32) -> f32 {
532+
unsafe { cmath::hypotf(self, other) }
533+
}
501534

502535
#[inline]
503-
fn sin(self) -> f32 { unsafe{intrinsics::sinf32(self)} }
536+
fn sin(self) -> f32 {
537+
unsafe { intrinsics::sinf32(self) }
538+
}
504539

505540
#[inline]
506-
fn cos(self) -> f32 { unsafe{intrinsics::cosf32(self)} }
541+
fn cos(self) -> f32 {
542+
unsafe { intrinsics::cosf32(self) }
543+
}
507544

508545
#[inline]
509-
fn tan(self) -> f32 { unsafe{cmath::tanf(self)} }
546+
fn tan(self) -> f32 {
547+
unsafe { cmath::tanf(self) }
548+
}
510549

511550
#[inline]
512-
fn asin(self) -> f32 { unsafe{cmath::asinf(self)} }
551+
fn asin(self) -> f32 {
552+
unsafe { cmath::asinf(self) }
553+
}
513554

514555
#[inline]
515-
fn acos(self) -> f32 { unsafe{cmath::acosf(self)} }
556+
fn acos(self) -> f32 {
557+
unsafe { cmath::acosf(self) }
558+
}
516559

517560
#[inline]
518-
fn atan(self) -> f32 { unsafe{cmath::atanf(self)} }
561+
fn atan(self) -> f32 {
562+
unsafe { cmath::atanf(self) }
563+
}
519564

520565
#[inline]
521-
fn atan2(self, other: f32) -> f32 { unsafe{cmath::atan2f(self, other)} }
566+
fn atan2(self, other: f32) -> f32 {
567+
unsafe { cmath::atan2f(self, other) }
568+
}
522569

523570
/// Simultaneously computes the sine and cosine of the number
524571
#[inline]
@@ -528,36 +575,52 @@ impl Float for f32 {
528575

529576
/// Returns the exponential of the number
530577
#[inline]
531-
fn exp(self) -> f32 { unsafe{intrinsics::expf32(self)} }
578+
fn exp(self) -> f32 {
579+
unsafe { intrinsics::expf32(self) }
580+
}
532581

533582
/// Returns 2 raised to the power of the number
534583
#[inline]
535-
fn exp2(self) -> f32 { unsafe{intrinsics::exp2f32(self)} }
584+
fn exp2(self) -> f32 {
585+
unsafe { intrinsics::exp2f32(self) }
586+
}
536587

537588
/// Returns the natural logarithm of the number
538589
#[inline]
539-
fn ln(self) -> f32 { unsafe{intrinsics::logf32(self)} }
590+
fn ln(self) -> f32 {
591+
unsafe { intrinsics::logf32(self) }
592+
}
540593

541594
/// Returns the logarithm of the number with respect to an arbitrary base
542595
#[inline]
543596
fn log(self, base: f32) -> f32 { self.ln() / base.ln() }
544597

545598
/// Returns the base 2 logarithm of the number
546599
#[inline]
547-
fn log2(self) -> f32 { unsafe{intrinsics::log2f32(self)} }
600+
fn log2(self) -> f32 {
601+
unsafe { intrinsics::log2f32(self) }
602+
}
548603

549604
/// Returns the base 10 logarithm of the number
550605
#[inline]
551-
fn log10(self) -> f32 { unsafe{intrinsics::log10f32(self)} }
606+
fn log10(self) -> f32 {
607+
unsafe { intrinsics::log10f32(self) }
608+
}
552609

553610
#[inline]
554-
fn sinh(self) -> f32 { unsafe{cmath::sinhf(self)} }
611+
fn sinh(self) -> f32 {
612+
unsafe { cmath::sinhf(self) }
613+
}
555614

556615
#[inline]
557-
fn cosh(self) -> f32 { unsafe{cmath::coshf(self)} }
616+
fn cosh(self) -> f32 {
617+
unsafe { cmath::coshf(self) }
618+
}
558619

559620
#[inline]
560-
fn tanh(self) -> f32 { unsafe{cmath::tanhf(self)} }
621+
fn tanh(self) -> f32 {
622+
unsafe { cmath::tanhf(self) }
623+
}
561624

562625
/// Inverse hyperbolic sine
563626
///

0 commit comments

Comments
 (0)