File: float_methods.rs

package info (click to toggle)
rustc 1.87.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 925,564 kB
  • sloc: xml: 158,127; python: 36,039; javascript: 19,761; sh: 19,737; cpp: 18,981; ansic: 13,133; asm: 4,376; makefile: 710; perl: 29; lisp: 28; ruby: 19; sql: 11
file content (46 lines) | stat: -rw-r--r-- 1,354 bytes parent folder | download | duplicates (10)
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
//@ run-pass
//! Tests the float intrinsics: min, max, abs, copysign

#![feature(f16, f128)]

const F16_MIN: f16 = 1.0_f16.min(0.5_f16);
const F16_MAX: f16 = 1.0_f16.max(0.5_f16);
const F16_ABS: f16 = (-1.0_f16).abs();
const F16_COPYSIGN: f16 = 1.0_f16.copysign(-2.0_f16);

const F32_MIN: f32 = 1.0_f32.min(0.5_f32);
const F32_MAX: f32 = 1.0_f32.max(0.5_f32);
const F32_ABS: f32 = (-1.0_f32).abs();
const F32_COPYSIGN: f32 = 1.0_f32.copysign(-2.0_f32);

const F64_MIN: f64 = 1.0_f64.min(0.5_f64);
const F64_MAX: f64 = 1.0_f64.max(0.5_f64);
const F64_ABS: f64 = (-1.0_f64).abs();
const F64_COPYSIGN: f64 = 1.0_f64.copysign(-2.0_f64);

const F128_MIN: f128 = 1.0_f128.min(0.5_f128);
const F128_MAX: f128 = 1.0_f128.max(0.5_f128);
const F128_ABS: f128 = (-1.0_f128).abs();
const F128_COPYSIGN: f128 = 1.0_f128.copysign(-2.0_f128);

fn main() {
    assert_eq!(F16_MIN, 0.5);
    assert_eq!(F16_MAX, 1.0);
    assert_eq!(F16_ABS, 1.0);
    assert_eq!(F16_COPYSIGN, -1.0);

    assert_eq!(F32_MIN, 0.5);
    assert_eq!(F32_MAX, 1.0);
    assert_eq!(F32_ABS, 1.0);
    assert_eq!(F32_COPYSIGN, -1.0);

    assert_eq!(F64_MIN, 0.5);
    assert_eq!(F64_MAX, 1.0);
    assert_eq!(F64_ABS, 1.0);
    assert_eq!(F64_COPYSIGN, -1.0);

    assert_eq!(F128_MIN, 0.5);
    assert_eq!(F128_MAX, 1.0);
    assert_eq!(F128_ABS, 1.0);
    assert_eq!(F128_COPYSIGN, -1.0);
}