From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: exceeding realmax or realmin values
Date: Fri, 26 Nov 2010 17:32:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <icoquk$hk$>
References: <icoib0$jvp$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1290792724 564 (26 Nov 2010 17:32:04 GMT)
NNTP-Posting-Date: Fri, 26 Nov 2010 17:32:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:690288

"Maarten " <> wrote in message <icoib0$jvp$>...
> Hi,
> Is it in any way possible to temporarily exceed the realmax or realmin value during calculations? For example if I want to find the value for A=Log(exp(1000)). Exp(1000) exceeds the realmax value, so it is infinite. This makes a also infinte. Is there a way to get the correct value for A, in this case 1000?
> Thanks
- - - - - - - - -
  When you would exceed 'realmax' it is as Bruno says a situation where you must modify your procedure.  In the example you give of log(exp(1000)) you could take advantage of rescaling the 1000 by using the identity

 log(exp(x*k)) = log(exp(x)^k) = k*log(exp(x))

If k were equal to ten and x were a hundred, these quantities on the right would fall well within the double floating point format's acceptable range of numbers.

  The designers of the 754 IEEE floating point standard for double precision provided 11 bits out of 64 for a two's exponent, 52 bits for the "significand" and 1 bit as sign.  The 'realmax' value has the exponent and significand values at their respective maximum possible values which gives a value of 2^1046*(2-2^-52) which is certainly a very large number, larger than the famous "google" and also larger by a very great margin than the total number of atoms in the known universe.

  You should be aware that a somewhat different situation prevails with very small numbers.  The value 'realmin' = 2^-1022 is the smallest floating point value that retains the full 53 bit accuracy in its significand.  However floating point numbers can be used in calculations that are as small as 2^-1074 without becoming zero.  The exponent becomes locked at 2^-1022 but the signficand can descend to as low as 2^-52 but with gradually reducing accuracy.  This has been called a "gradual underflow" as opposed to the sudden "flush to zero" that many previous floating point systems used.  To retain full accuracy however the numbers should not descend below 'realmin'.

  This system was planned to take best advantage of the information that could be crammed into only 64 bits, in the opinion of its designers.  A user of the system must always take into account the limitations of the number representations in that system and adjust their algorithm accordingly.

Roger Stafford