approx(Ans) oddity
12-27-2023, 05:01 PM
Post: #1
 BruceH Senior Member Posts: 510 Joined: Dec 2013
approx(Ans) oddity
Anyone seeing odd results coming from approx(Ans) in Home?

On my G2 Prime, version 2023 04 13, which has been used for a bit of everything (programming, general calculations etc), I discovered by chance that approx(Ans) resulted in a 6 on the stack regardless of what was actually top. Just Ans on its own gave the top of stack as expected. A soft reset (On+Apps+Esc) wouldn't clear the problem.

In the end I had to do a paperclip reset.

Now I wonder what other oddities can be so persistent?
12-27-2023, 06:27 PM
Post: #2
 Dougggg Member Posts: 128 Joined: Dec 2013
RE: approx(Ans) oddity
It appears in my experience that approx is getting Ans from Cas not Home for me
12-28-2023, 12:39 AM (This post was last modified: 12-28-2023 12:39 AM by Joe Horn.)
Post: #3
 Joe Horn Senior Member Posts: 2,005 Joined: Dec 2013
RE: approx(Ans) oddity
(12-27-2023 06:27 PM)Dougggg Wrote:  It appears in my experience that approx is getting Ans from Cas not Home for me

That is correct. The approx() function is a CAS function, so approx(Ans) interprets "Ans" to mean the current value of CAS's Ans, which is different from Home's Ans. Similar unexpected results come from simplify(Ans) in Home, for the same reason.

One way to evaluate Home's Ans when you're in Home view is EVAL(Ans), which thankfully is on the keyboard (Shift comma).

<0|ɸ|0>
-Joe-
12-28-2023, 03:13 AM
Post: #4
 Albert Chan Senior Member Posts: 2,682 Joined: Jul 2018
RE: approx(Ans) oddity
(12-28-2023 12:39 AM)Joe Horn Wrote:  One way to evaluate Home's Ans when you're in Home view is EVAL(Ans)

Nice trick!
It would be even better if Ans really mean EVAL(Ans), by default.

For now, this is a temporary fix.
Code:
EXPORT ANS() BEGIN EVAL(Ans); END;

HOME> 1/(2+3/4)      → 0.363636363636
HOME> exact(ANS)     → 4/11
HOME> float(ANS)      → 0.363636363636
12-28-2023, 06:40 PM (This post was last modified: 12-28-2023 06:41 PM by BruceH.)
Post: #5
 BruceH Senior Member Posts: 510 Joined: Dec 2013
RE: approx(Ans) oddity
Thanks for the answers. It seems there is at least one definite bug and a second, possible bug.

Firstly, I can repeat the issue by:
1. reset the calc (On+Apps+Esc)
2. go into CAS and put 6 on the stack
3. go back to Home and put 3 on the stack
4. press ≈ Ans (to get approx(Ans)) and the result is 6 not 3

This is what I'm calling the possible bug because I feel that functions selected from the keyboard in Home mode, including ≈, should only be affected by whatever is set in Home. After all, SIN gives you SIN() in Home mode but sin() in CAS mode.

Now
1. reset the calc (On+Apps+Esc)
2. go into CAS mode and verify the stack is empty (don't add anything to it)
3. go back to Home and do approx(Ans)

and you still get 6. This is the definite bug - both stacks were empty.
12-28-2023, 08:12 PM
Post: #6
 gehakte_bits Junior Member Posts: 42 Joined: Dec 2021
RE: approx(Ans) oddity
See 'Ans' as a variable, not the last visible data on the stack.
Clear the stack (shift-Clear) and recall Ans.

A reset restored the last Ans prior to the reset.
12-28-2023, 08:41 PM
Post: #7
 Wes Loewer Senior Member Posts: 459 Joined: Jan 2014
RE: approx(Ans) oddity
(12-28-2023 06:40 PM)BruceH Wrote:  Now
1. reset the calc (On+Apps+Esc)
2. go into CAS mode and verify the stack is empty (don't add anything to it)
3. go back to Home and do approx(Ans)

and you still get 6. This is the definite bug - both stacks were empty.

Ans gives the result of the last calculation, which is not necessarily the value at the bottom on the history.

For example, enter the following.
Code:
1+2          3 3+4          7 5+6         11

Now press the Del button until you only have
Code:
1+2          3

If you now use Ans, it will return 11, not 3, since 11 was the last calculated result.
Code:
1+2          3 Ans          11

Then there's the matter of clearing the memory. It seems that clearing the memory resets Home Ans to 0 but CAS Ans seems to survive the memory clear. This might actually be a bug.
12-29-2023, 12:34 AM
Post: #8
 BruceH Senior Member Posts: 510 Joined: Dec 2013
RE: approx(Ans) oddity
Here's some more weirdness...

Go into Home mode and do Ans(8), say, when the stack is empty or has fewer than 8 levels and you get "Error: invalid input" as you'd expect.

Now do 'approx(Ans(8))' when the CAS stack is empty or has fewer than 8 levels. The answer you get is the same as 'approx(Ans)'.

Looks like Ans is treated as an array in Home mode but not in CAS mode.

I think we should have a go at trying to reach a consensus on what we think should happen so that if/when Moravia get a chance to do some bug fixing, we can at least be ready to show them what we'd like to see happen regarding Ans and Ans().
12-29-2023, 01:20 PM
Post: #9
 Joe Horn Senior Member Posts: 2,005 Joined: Dec 2013
RE: approx(Ans) oddity
(12-29-2023 12:34 AM)BruceH Wrote:  Here's some more weirdness... [snip]

I think we should have a go at trying to reach a consensus on what we think should happen so that if/when Moravia get a chance to do some bug fixing, we can at least be ready to show them what we'd like to see happen regarding Ans and Ans().

These behaviors of Ans in Home and CAS are neither bugs nor weirdnesses. Press Ans Help to see the built-in Help screen about Ans, which details these behaviors.

<0|ɸ|0>
-Joe-
12-29-2023, 01:36 PM
Post: #10
 BruceH Senior Member Posts: 510 Joined: Dec 2013
RE: approx(Ans) oddity
Just because it's written down that it behaves weirdly and inconsistently doesn't mean that it isn't weird and inconsistent! :-))

But I take your point that I should have looked at the Help as being the most up to date documentation. My apologies for the noise.

PS: In Home try Ans(-1).
 « Next Oldest | Next Newest »