[S] Behavior of trunc(x)

John (jhfslf@swva.net)
Tue, 22 Sep 1998 21:54:21 -0400


Hello S-Users,

This may be an old one that I've missed but can anyone explain the behavior
illustrated below?

This is happening on S-Plus version 3.2 release 1, running under NT 4.0 on
a Pentium II 266.

# Exhibit 1: Long way to generate integers, but OK
> for(x in (10:19)/10)print((10*(x-trunc(x))))
[1] 0
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
# Exhibit 2: trunc those integers ??
> for(x in (10:19)/10)print(trunc(10*(x-trunc(x))))
[1] 0
[1] 1
[1] 1
[1] 3
[1] 3
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
# Exhibit 3: It even seems fickle (change the input range)
> for(x in (30:39)/10)print(trunc(10*(x-trunc(x))))
[1] 0
[1] 1
[1] 2
[1] 2
[1] 3
[1] 5
[1] 6
[1] 7
[1] 7
[1] 9
>
All comments welcome!

Thanks

John
- John Fennick
Tel: (540) 552-0052
Fax: (540) 552-0261 (Telephone first for setup)
e-mail: jhfslf@swva.net
alt: j.fennick@ieee.org
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news