[e-lang] Defensive consistency and integer overflow

Bill Frantz frantz at pwpconsult.com
Sun Sep 23 21:11:26 EDT 2007


erights at gmail.com (Mark Miller) on Sunday, September 23, 2007 wrote:

>The irony is that defensive consistency doesn't need arbitrary
>precision integers. It would have been adequate for fixed precision
>integers to either throw an exception or became a NaN when exceeding
>its precision limit. Today, all instruction sets make available an
>overflow bit on integer ALU operations. AFAIK, all languages with
>fixed precision "integer" arithmetic ignore this bit and make it
>inaccessible.

The IBM 370 had a mode that would cause integer overflow to trap.  This
mode could be set by a user-mode instruction.

Out of curiosity, do any compilers take the statement:

if ( i>5 || i<0 ) error_report();

or the equivalent (for integers):

if ( (i>5) | (i<0) ) error_report();

and compile the test using unsigned arithmetic (in 370 assembler):

L  reg,i         load i into a register
CL reg,=F'5'     unsigned compare with an integer 5
BH error_report  branch if reg>5 because negative numbers are much greater

Cheers - Bill

---------------------------------------------------------------------------
Bill Frantz        |"We used to quip that "password" is the most common
408-356-8506       | password. Now it's 'password1.' Who said users haven't
www.periwinkle.com | learned anything about security?" -- Bruce Schneier



More information about the e-lang mailing list