rnorm() with sd=0

Ben Bolker ben@eno.Princeton.EDU
Sat, 9 Jan 1999 15:45:01 -0500 (EST)


  Is there a compelling reason why

rnorm(1,mean=m,sd=0)

can't return m instead of NaN?

  The following (trivial) patch makes the change.

*** rnorm.c.orig	Sat Jan  9 15:39:41 1999
--- rnorm.c	Sat Jan  9 15:39:50 1999
***************
*** 35,43 ****
  #ifdef IEEE_754
          !finite(mu) || !finite(sigma) ||
  #endif
! 	sigma <= 0.0) {
  	ML_ERROR(ME_DOMAIN);
  	return ML_NAN; 
!     }
!     return mu + sigma * snorm();
  }
--- 35,46 ----
  #ifdef IEEE_754
          !finite(mu) || !finite(sigma) ||
  #endif
! 	sigma < 0.0) {
  	ML_ERROR(ME_DOMAIN);
  	return ML_NAN; 
!     } else
!     if (sigma==0.0)
!        return mu;
!     else 
!        return mu + sigma * snorm();
  }

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._