Skip to content
Back to formatted view

Raw Message

Message-ID: <4992B46D.6060508@cam.ac.uk>
Date: 2009-02-11T11:20:13Z
From: robin hankin
Subject: How to handle large numbers?
In-Reply-To: <339934530902110240y1cf64fd6u2101c3a706e1db41@mail.gmail.com>

Feng

checkout the Brobdingnag package:


 > library(Brobdingnag)
 > exp(1000)/(exp(1007)+5)
[1] NaN

 > as.numeric(exp(as.brob(1000))/(exp(as.brob(1007))+5))
[1] 0.000911882
 >

Feng Li wrote:
> Dear R,
>
> I have two questions:
>
> 1, Why both R and Matlab give 0*Inf==NaN? To my knowledge, it should be zero
> mathematically. Am I right?
>
> 2, I need to calculate e.g. exp(a)/(exp(b)+c), where both a and b are very
> large numbers (>>1000, e.g a=1000, b=1007, and c=5). R gives me NaN when I
> use the following command:
>
>   
>> exp(1000)/(exp(1007)+5)
>>     
> [1] NaN
>
> I am pretty sure this should be close to zero. My question is whether there
> is a general way to solve this kind of question or should I do some settings
> before computing?
>
>
> Thanks in advance!
>
>
> Feng
>
>
>
>   


-- 
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877