Overflow

While the use of scientific notation expands the range of numbers we can represent with fixed-size chunks of data, it still doesn't cover arbitrarily large numbers. Some numbers are just too big to fit into a fixed-size number representation. For example,

#displaymath74072#

can't be represented, because the exponent 500 won't fit into two digits, and the mantissa is as large as it can be. Numbers that are too large for our representation schema can arise during a computation. For example, two numbers that we can represent can add up to a number that we cannot represent:

  <#43485#>(inex+<#43485#> <#43486#>(create-inex<#43486#> <#43487#>50<#43487#> <#43488#>+1<#43488#> <#43489#>99)<#43489#>
         <#43490#>(create-inex<#43490#> <#43491#>50<#43491#> <#43492#>+1<#43492#> <#43493#>99))<#43493#> 
<#43494#>=<#43494#> <#43495#>(create-inex<#43495#> <#43496#>100<#43496#> <#43497#>+1<#43497#> <#43498#>99)<#43498#> 
which violates the data contract, or
  <#43506#>(inex+<#43506#> <#43507#>(create-inex<#43507#> <#43508#>50<#43508#> <#43509#>+1<#43509#> <#43510#>99)<#43510#>
         <#43511#>(create-inex<#43511#> <#43512#>50<#43512#> <#43513#>+1<#43513#> <#43514#>99))<#43514#> 
<#43515#>=<#43515#> <#43516#>(create-inex<#43516#> <#43517#>10<#43517#> <#43518#>+1<#43518#> <#43519#>100)<#43519#> 
which also breaks the contract for <#67954#><#43523#>inex<#43523#><#67954#> structures. When the result of <#67955#><#43524#>inex<#43524#><#67955#> arithmetic produces numbers that are too large to be represented, we say (arithmetic) <#67956#><#43525#>OVERFLOW<#43525#><#67956#> occurred. When overflow occurs, some language implementations signal an error and stop the computation. Others designate some symbol, called infinity, for all numbers that are too large. Arithmetic operations are aware of infinity and propagate it.

<#43526#>Negative Numbers<#43526#>:\ If our <#67957#><#43527#>inex<#43527#><#67957#> structures had a sign field for the mantissa, then two negative numbers can add up to one that is so negative that it can't be represented either. This is also called overflow, though to emphasize the distinction people sometimes say overflow in the negative direction.~<#67958#><#67958#>
<#43532#>Exercise 33.2.1<#43532#> DrScheme's inexact number system uses an infinity value to deal with overflow. Determine the integer <#67959#><#43534#>n<#43534#><#67959#> such that <#67960#><#43535#>(expt<#43535#><#43536#> <#43536#><#43537#>#<#43537#><#43538#>i10.<#43538#>\ <#43539#>n)<#43539#><#67960#> is still an inexact Scheme number and <#67961#><#43540#>(expt<#43540#>\ <#43541#>#<#43541#><#43542#>i10.<#43542#>\ <#43543#>(+<#43543#>\ <#43544#>n<#43544#><#43545#> <#43545#><#43546#>1))<#43546#><#67961#> is approximated with infinity. <#43547#>Hint:<#43547#> Use a function to compute <#67962#><#43548#>n<#43548#><#67962#>.~ external Solution<#67963#><#67963#>