Arithmethic overflow should not raise an exception

If you need saturating operations you can do as I pointed before

lib LibIntrinsics
  fun sat_uadd8 = "llvm.uadd.sat.i8"(a : UInt8, b : UInt8) : UInt8
end

module Intrinsics
  def self.sadd(a : UInt8, b : UInt8) : UInt8
    LibIntrinsics.sat_uadd8(a, b)
  end
end

pp! a = 100_u8                     # => 100
pp! a = Intrinsics.sadd(a, 100_u8) # => 200
pp! a = Intrinsics.sadd(a, 100_u8) # => 255
1 Like