harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

35-floats.ha (1950B)


      1 fn measurements() void = {
      2 	assert(size(f32) == align(f32));
      3 	assert(size(f32) == align(f32));
      4 };
      5 
      6 fn signed_casts() void = {
      7 	let a = 20f64;
      8 	let f = a: f32;
      9 	assert(f == 20f32);
     10 	let i = a: i8;
     11 	assert(i == 20);
     12 	let i = a: i16;
     13 	assert(i == 20);
     14 	let i = a: i16;
     15 	assert(i == 20);
     16 	let i = a: i32;
     17 	assert(i == 20);
     18 	let i = a: i64;
     19 	assert(i == 20);
     20 
     21 	let a = 20f32;
     22 	let f = a: f64;
     23 	assert(f == 20f64);
     24 	let i = a: i8;
     25 	assert(i == 20);
     26 	let i = a: i16;
     27 	assert(i == 20);
     28 	let i = a: i16;
     29 	assert(i == 20);
     30 	let i = a: i32;
     31 	assert(i == 20);
     32 	let i = a: i64;
     33 	assert(i == 20);
     34 
     35 	let a = 20i8;
     36 	let f = a: f32;
     37 	assert(f == 20f32);
     38 	let f = a: f64;
     39 	assert(f == 20f64);
     40 
     41 	let a = 20i16;
     42 	let f = a: f32;
     43 	assert(f == 20f32);
     44 	let f = a: f64;
     45 	assert(f == 20f64);
     46 
     47 	let a = 20i32;
     48 	let f = a: f32;
     49 	assert(f == 20f32);
     50 	let f = a: f64;
     51 	assert(f == 20f64);
     52 
     53 	let a = 20i64;
     54 	let f = a: f32;
     55 	assert(f == 20f32);
     56 	let f = a: f64;
     57 	assert(f == 20f64);
     58 };
     59 
     60 fn unsigned_casts() void = {
     61 	let a = 20f64;
     62 	let f = a: f32;
     63 	assert(f == 20f32);
     64 	let i = a: u8;
     65 	assert(i == 20);
     66 	let i = a: u16;
     67 	assert(i == 20);
     68 	let i = a: u16;
     69 	assert(i == 20);
     70 	let i = a: u32;
     71 	assert(i == 20);
     72 	let i = a: u64;
     73 	assert(i == 20);
     74 
     75 	let a = 20f32;
     76 	let f = a: f64;
     77 	assert(f == 20f64);
     78 	let i = a: u8;
     79 	assert(i == 20);
     80 	let i = a: u16;
     81 	assert(i == 20);
     82 	let i = a: u16;
     83 	assert(i == 20);
     84 	let i = a: u32;
     85 	assert(i == 20);
     86 	let i = a: u64;
     87 	assert(i == 20);
     88 
     89 	let a = 20u8;
     90 	let f = a: f32;
     91 	assert(f == 20f32);
     92 	let f = a: f64;
     93 	assert(f == 20f64);
     94 
     95 	let a = 20u16;
     96 	let f = a: f32;
     97 	assert(f == 20f32);
     98 	let f = a: f64;
     99 	assert(f == 20f64);
    100 
    101 	let a = 20u32;
    102 	let f = a: f32;
    103 	assert(f == 20f32);
    104 	let f = a: f64;
    105 	assert(f == 20f64);
    106 
    107 	let a = 20u64;
    108 	let f = a: f32;
    109 	assert(f == 20f32);
    110 	let f = a: f64;
    111 	assert(f == 20f64);
    112 };
    113 
    114 
    115 export fn main() void = {
    116 	// TODO: test parsing, compile-time evaluation
    117 	measurements();
    118 	signed_casts();
    119 	unsigned_casts();
    120 };