[R] Annoyance with %/%
jim holtman
jholtman at gmail.com
Wed Mar 11 16:37:40 CET 2015
shouldn't your last expression be:
if (any(tst)) big.vector.1[tst] <- big.vector.2[tst]
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
On Wed, Mar 11, 2015 at 11:14 AM, William Dunlap <wdunlap at tibco.com> wrote:
> > %/% which, BTW,
> > violated the sacred rule that for all a, and non-zero b:
> >
> > a = b * (a %/% b) + a %% b
> >
> > Namely, that Inf %/% n is not Inf, but NaN.
>
> But the other sacred rule is that a%%b is >=0 and <b.
>
> By the way, you will run into problems with %% long before Inf. E.g.,
> > (1 + 2^53) %% 2 # 1 if you had infinite precision
> [1] 0
> > (2 + 2^53) %% 2
> [1] 0
> Warning message:
> probable complete loss of accuracy in modulus
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Wed, Mar 11, 2015 at 4:25 AM, ALBERTO VIEIRA FERREIRA MONTEIRO <
> albmont at centroin.com.br> wrote:
>
> > I've just found an annoyance with the behaviour of %/% which, BTW,
> > violated the sacred rule that for all a, and non-zero b:
> >
> > a = b * (a %/% b) + a %% b
> >
> > Namely, that Inf %/% n is not Inf, but NaN.
> >
> > Why is this so? It's an annoyance, because in expressions like:
> >
> > big.vector.1[a, b, c] <- big.vector.2[a, b, c] %/% n
> >
> > we must treat Inf and -Inf as exceptions, when a simple division does
> > not have these exceptions
> >
> > BTW, I treated this exception the way Grace Hopper would be proud of,
> > namely,
> > "it's easier to ask forgiveness than it is to get permission", but at
> > the cost of memory:
> >
> > big.vector.1 <- big.vector.2
> > big.vector.1[a, b, c] <- big.vector.2[a, b, c] %/% n
> > tst <- is.nan(big.vector.1)
> > if (any(tst)) big.vector.1[tst] <- big.vector.2
> >
> > Alberto Monteiro
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list