From tomas.kalibera at gmail.com  Tue Jan 24 10:32:53 2017
From: tomas.kalibera at gmail.com (Tomas Kalibera)
Date: Tue, 24 Jan 2017 10:32:53 +0100
Subject: [Rd] NaN behavior of cumsum
In-Reply-To: <9A7219BE-A728-45E0-B02E-E1834841D749@oracle.com>
References: <9A7219BE-A728-45E0-B02E-E1834841D749@oracle.com>
Message-ID: <315b7608-3ddf-f6a4-e283-f485a22c194a@gmail.com>

Hi Lukas,

thanks for the report. I've changed cumsum so that it is now consistent 
with cumprod wrt to NA/NaN propagation.
Now NaN is not turned into NA unnecessarily.

Still please be aware that generally NaNs may become NAs in R (on some 
platforms/compilers)
?NaN says

"Computations involving ?NaN? will return ?NaN? or perhaps ?NA?:
which of those two is not guaranteed and may depend on the R
platform (since compilers may re-order computations)."

Best
Tomas

On 01/20/2017 02:52 PM, Lukas Stadler wrote:
> Hi!
>
> I noticed that cumsum behaves different than the other cumulative functions wrt. NaN values:
>> values <- c(1,2,NaN,1)
>> for ( f in c(cumsum, cumprod, cummin, cummax)) print(f(values))
> [1]  1  3 NA NA
> [1]   1   2 NaN NaN
> [1]   1   1 NaN NaN
> [1]   1   2 NaN NaN
>
> The reason is that cumsum (in cum.c:33) contains an explicit check for ISNAN.
> Is that intentional?
> IMHO, ISNA would be better (because it would make the behavior consistent with the other functions).
>
> - Lukas
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] NaN behavior of cumsum
Tomas Kalibera