sourcelibs/Fixed/demos/overflow.xtl

1⍝!/usr/bin/env xetal 2⍝ What an 8-bit adder does with 100 + 100: the exact sum is 200, which 3⍝ does not fit in 8 signed bits, so the circuit answers -56; at 16 4⍝ bits it fits. Run with "just demo-lib Fixed overflow". 5ᶠˣ⁼u̲se< "Fixed" 6100 + 100 ⍝ the evaluator's 64-bit Int 78 ᶠˣo̲verflow? 200 ⍝ 1: not in -128 to 127 88 ᶠˣw̲rap 200 ⍝ what the 8-bit adder gives 98 ᶠˣb̲its 200 ⍝ its bits: the top bit set, so negative 108 ᶠˣs̲at 200 ⍝ a saturating adder would stop at 127 1116 ᶠˣw̲rap 200 ⍝ a 16-bit adder is fine 1216 ᶠˣh̲ex 200