Bug 15734 - Calculation error in using function pbinom
Summary: Calculation error in using function pbinom
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.0.2
Hardware: ix86 (32-bit) Windows 32-bit
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2014-03-31 00:46 UTC by John Xie
Modified: 2014-04-10 19:11 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Xie 2014-03-31 00:46:35 UTC
Error examples:

If we do 'pbinom(1,10^10,0.5)', R returns answer zero as we expected;
If we do 'pbinom(1,3.239*10^10,0.5)', R returns answer zero as we expected;
If we do 'pbinom(1,3.241*10^10,0.5)', R returns answer zero as we expected;
However,
If we do 'pbinom(1,3.240*10^10,0.5)', R returns answer 'NaN' as we unexpected!
Very odd, although it is a minor bug as my understanding.
Comment 1 Peter Dalgaard 2014-03-31 07:34:56 UTC
FAQ 7.31:

> pbinom(1,3.240*10^10,0.5)
[1] NaN
Warning message:
In pbinom(1, 3.24 * 10^10, 0.5) : NaNs produced
> pbinom(1,3240*10^7,0.5)
[1] 0
> 3.240*10^10-3240*10^7
[1] 3.814697e-06
Comment 2 Martin Maechler 2014-03-31 08:16:15 UTC
FAQ 7.31 is correct.
OTOH, note that our check is R_nonint(n)   ['n' is R-level 'size'],
and that is defined in nmath.h as

# define R_nonint(x) 	  (fabs((x) - R_forceint(x)) > 1e-7)

and R_forceint() is typically nearbyint() nowadays,
but I think we should improve the check to become relative, at least for non-small x.