hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

README (516B)


      1 math::checked provides safe integer arithmetic functions that check for
      2 overflow.
      3 
      4 The functions add*, sub* and mul* perform wrapping integer arithmetic, with the
      5 same semantics as the +, -, and * operators.
      6 
      7 	const (res, overflow) = math::addi32(types::I32_MAX, 1);
      8 	assert(res == types::I32_MIN);
      9 	assert(overflow);
     10 
     11 The functions sat_* perform saturating integer arithmetic, which clamp the
     12 result value to the range of the type.
     13 
     14 	const res = math::sat_addi32(types::I32_MAX, 1);
     15 	assert(res == types::I32_MAX);