# HP Forums

Full Version: [WP34s] RSD function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

The 34s features a very useful function that rounds a value to a certain number of significant digits - the RSD function. Some time ago I wrote a short program based on the "calculator forensics" routine that determines the perfect result an n-digit calculator should return:

```001 LBL A
002 STO 00
003  9
004 SIN
005 RSD->00
006 COS
007 RSD->00
008 TAN
009 RSD->00
010 ATAN
011 RSD->00
012 ACOS
013 RSD->00
014 ASIN
015 RSD->00
016 RTN
```
Enter a number of digits (n), run the program (preferably in double precision) and the perfect result for a perfect n-digit machine will be returned.
```  12  [A]  8,99999864267
10  [A]  9,000417403
6  [A]  9,32631
3  [A]  0
```
Now try this...
```   0  [A]
```
...and see what you get.

Then single-step through the program and see what happens at step 012/013 where ACOS returns 90 degrees which is then rounded to 0 significant digits.

Finally try the same directly from the keyboard:

```   90  RSD 0
```
and compare the result with the previous one.

Which leads to the question: what is RSD 0 supposed to return?

Dieter

RSD 0 is rubbish per definition. 1 is the lowest value making sense. We'll catch that bug - thanks for reporting.

d:-)

Well, in a way RSD 0 can make sense:

```0,02   RSD 0  =>  0,01
0,08   RSD 0  =>  0,1
3   RSD 0  =>  1
6   RSD 0  =>  10
314   RSD 0  =>  100
628   RSD 0  =>  1000
4999  RSD 0  =>  1000
5000  RSD 0  =>  10000
```
But limiting the argument for RSD to values >= 1 is fine by me either. ;-)

Please also note that the current implementation may return different results in run and program mode. 90 RSD 0 here returns either 1E-14 or 10. Maybe you can check this as well.

Dieter

Edited: 27 Jan 2013, 2:07 p.m. after one or more responses were posted

In other words, RSD 0 in Dieter's mind is simply a "power of 10 orders of magnitude" function. It always returns "1. E X", where X is the appropriate order of magnitude. Or, presumably, 0.

Cheers,

Doug

If (!) RSD 0 is accepted it may behave as follows:

``` SIGN
RCL L
STO+ X
EXPT
X<0?     // since SDL and SDR do not accept negative arguments
SKIP 003 // both cases have to be handled separately
X<>Y
SDL->Y
RTN
+/-
X<>Y
SDR->Y
RTN
```
This rounds X to the next closest power of 10. Which IMHO is the logical continuation of the way RSD works otherwise:
```  X      RSD 2      RSD 1      RSD 0
------------------------------------
0,333    0,33       0,3        0,1
0,877    0,88       0,9        1
314      310        300        100
682      680        700        1000
-47      -47        -50        -10
-88      -88        -90       -100
------------------------------------
```
Dieter

Interesting continuation of the RSD function. Nevertheless I prefer stopping with RSD 1 for ... ummh ... philosophical reasons. A number can feature one or more significant digits. If it would feature zero significant digits, its overall significance would vanish. Hope this is logical.

d:-)

Rounding modes?

- Pauli

Dieter,

Quote:
Please also note that the current implementation may return different results in run and program mode. 90 RSD 0 here returns either 1E-14 or 10. Maybe you can check this as well.

I've checked and must confirm this. No idea, however, why
0 COS RSD 0
returns 1e-14. BTW, this occurs both in manual mode and if called from a program - reproducible as it ought to be, at least.

d:-?

RM is 0.

Dieter

Try this (in DEG mode):

``` 0 ACOS   => 90
RSD 0    => 1E-14

1 ASIN   => 90
RSD 0    => 1E-14

90
RSD 0    => 10
```
Both the emulator (3.2 3350) and the "real thing" (3.2 3360) behave this way. So, in which way is the 90 returned by ACOS different from the same value keyed in manually?

Finally, try this:

``` 0 ACOS   => 90
0 +      => 90
RSD 0    => 10

1 ASIN   => 90
1 x      => 90
RSD 0    => 10

90
RSD 0    => 10
```
It's hard to describe, but there seems to be some kind of ..."leftover" from the trig function that is removed with the next operation (here +0 resp. x1).

Any idea?

Dieter

Edited: 28 Jan 2013, 2:58 p.m.

Quote:
So, in which way is the 90 returned by ACOS different from the same value keyed in manually? ... It's hard to describe, but there seems to be some kind of ..."leftover" from the trig function that is removed with the next operation (here +0 resp. x1).

Any idea?

Not yet. But we are going to get rid of RSD 0 anyway (though this behaviour shall be explained).

d:-)

Build 3363 doesn't allow RSD 0 anymore.

d:-)