Advertisement
cwchen

[Rust] Show the boundary of various number types

Aug 22nd, 2017
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.38 KB | None | 0 0
  1. // Call related modules in standard library
  2. use std::{i8, i16, i32, i64, isize};
  3. use std::{u8, u16, u32, u64, usize};
  4. use std::{f32, f64};
  5.  
  6. fn main() {
  7.     // signed, fixed-width integers
  8.     println!("i8 min: {}, max: {}", i8::min_value(), i8::max_value());
  9.     println!("i16 min: {}, max: {}", i16::min_value(), i16::max_value());
  10.     println!("i32 min: {}, max: {}", i32::min_value(), i32::max_value());
  11.     println!("i64 min: {}, max: {}", i64::min_value(), i64::max_value());
  12.  
  13.     // unsigned, fixed-width integers
  14.     println!("u8 min: {}, max: {}", u8::min_value(), u8::max_value());
  15.     println!("u16 min: {}, max: {}", u16::min_value(), u16::max_value());
  16.     println!("u32 min: {}, max: {}", u32::min_value(), u32::max_value());
  17.     println!("u64 min: {}, max: {}", u64::min_value(), u64::max_value());
  18.  
  19.     // variable-width integers (platform dependant)
  20.     println!("isize min: {}, max: {}",
  21.              isize::min_value(),
  22.              isize::max_value());
  23.     println!("usize min: {}, max: {}",
  24.              usize::min_value(),
  25.              usize::max_value());
  26.  
  27.     // floating point numbers
  28.     println!("f32 min: {}, max: {}, min positive: {}",
  29.              f32::MIN,
  30.              f32::MAX,
  31.              f32::MIN_POSITIVE);
  32.     println!("f64 min: {}, max: {}, min positive: {}",
  33.              f64::MIN,
  34.              f64::MAX,
  35.              f64::MIN_POSITIVE);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement