help with exact command. [Solved]
|
04-25-2016, 07:54 PM
(This post was last modified: 04-25-2016 11:18 PM by Spybot.)
Post: #1
|
|||
|
|||
help with exact command. [Solved]
Hello!
Yeah I know this may seem ridiculously easy, but I'm trying to convert 0.333 to 1/3 ... but it resulted to be not as simple as I thought, perhaps someone has another approach!? EXPORT z() BEGIN LOCAL M; 5▶HFormat; 3▶HDigits; M:=0.333; M:=exact(M); PRINT(M); END; Thank You. Spybot. |
|||
04-25-2016, 08:13 PM
Post: #2
|
|||
|
|||
RE: help with exact command.
The issue is that 0.333 is quite different from 1/3, how can the Prime guess that the result you're expecting is the fraction 1/3 while the fraction 333/1000 is exactly equal to 0.333?
You need to provide at less 10 significant digits to get 1/3: exact(0.3333333333)=1/3 |
|||
04-25-2016, 08:33 PM
(This post was last modified: 04-25-2016 08:56 PM by Spybot.)
Post: #3
|
|||
|
|||
RE: help with exact command.
(04-25-2016 08:13 PM)Didier Lachieze Wrote: The issue is that 0.333 is quite different from 1/3, how can the Prime guess that the result you're expecting is the fraction 1/3 while the fraction 333/1000 is exactly equal to 0.333? I can make 0.333 to become 1/3 by changing some HOMEsettings [number format:rounded & HDigits to 3]... it'll do the trick though, the thing is that... when I try to replicate those settings from within a program and attempt to do the same operation... it's not working as expected! EXPORT z() BEGIN LOCAL M; 5▶HFormat; 3▶HDigits; M:=0.333; M:=exact(M); PRINT(M); END; Spybot. |
|||
04-25-2016, 09:27 PM
(This post was last modified: 04-25-2016 09:27 PM by DrD.)
Post: #4
|
|||
|
|||
RE: help with exact command.
Didier has given you the answer. Another way to do it would be to change:
M:=1/3; // Instead of M:=0.333 Then you would be able to see that approx(M) = 0.333 (to what ever your settings are), while exact(M) = 1/3. -Dale |
|||
04-25-2016, 10:20 PM
Post: #5
|
|||
|
|||
RE: help with exact command.
(04-25-2016 08:33 PM)Spybot Wrote: I can make 0.333 to become 1/3 by changing some HOMEsettings [number format:rounded & HDigits to 3]... it'll do the trick though, the thing is that... when I try to replicate those settings from within a program and attempt to do the same operation... it's not working as expected! Changing the HOME settings as you do has an impact on the [a b/c] key in Home but not on the CAS exact() function which depends on the value of the CAS epsilon setting. The following program does what you're looking for: Code: EXPORT z() Note that the line: Code: CAS("epsilon:=saved_ep"); |
|||
04-25-2016, 11:18 PM
(This post was last modified: 04-26-2016 12:30 AM by Spybot.)
Post: #6
|
|||
|
|||
RE: help with exact command.
Yes, that's what I'm talking about, I didn't expect epsilon had something to do with the thing I was trying to do here, but I see it definitely has. in fact this is exactly what I was looking for, Thanks Didier.
A couple of hours ago I did notice that, no mater what changes I made to the HOME settings, they did't affect the way CAS was treating objects in my program. but since epsilon is a CAS setting, I see it does have an impact. Now I found a use for this setting(epsilon), which I used to consider as an untouched setting. Thanks again for your help! Spybot. |
|||
04-27-2016, 06:02 AM
(This post was last modified: 04-27-2016 03:26 PM by Spybot.)
Post: #7
|
|||
|
|||
RE: help with exact command. [Solved]
Didier Lachieze : Hello....
We can actually restore epsilon on FW 8151... EXPORT z() BEGIN LOCAL M; PRINT; CAS("0.001▶epsilon"); PRINT("temporary epsilon ="+CAS("epsilon")); M:=0.333; M:=exact(M); PRINT("number...= "+M); CAS("0.00000000001▶epsilon"); PRINT("epsilon already restored="+CAS("epsilon")); END; I know the User might have a different value assigned to epsilon, that's the part I'm still figuring out. Spybot. |
|||
04-27-2016, 08:03 AM
Post: #8
|
|||
|
|||
RE: help with exact command. [Solved]
(04-27-2016 06:02 AM)Spybot Wrote: We can actually restore epsilon on FW 8151... Yes it's possible with 8151 but it's much simpler with the latest firmware thanks to the CAS access to local variables … On 8151, instead of restoring a fixed value as in your example: Code: CAS("0.00000000001▶epsilon"); Code: STRING(saved_epsilon)+"▶epsilon"▶restore_epsilon; So this program should work on both 8151 and 10077 (not tested on 8151 as I don’t have a 8151 firmware on hand): Code: EXPORT z() |
|||
04-28-2016, 07:58 AM
(This post was last modified: 04-28-2016 07:59 AM by retoa.)
Post: #9
|
|||
|
|||
RE: help with exact command. [Solved]
I wrote a little program to transform periodic numbers into fractions:
Code:
la is the length of the antiperiod, 0 if no antiperiod it returns a list with numerator and denominator of the fracion. examples: 0.33333333 periodo(0.3,0) -> {1, 3} 2.353535353535 periodo(2.35,0) -> {233, 99} 3.456767676767 (the periodical part is 67, the antiperiod is 45, 2 digit length) periodo(3.4567,2) -> {17111, 4950} It should work independently of the number format settings. |
|||
04-28-2016, 11:13 AM
Post: #10
|
|||
|
|||
RE: help with exact command. [Solved]
thank you, retoa, nice program :-)
Salvo ∫aL√0mic (IT9CLU) :: HP Prime 50g 41CX 71b 42s 39s 35s 12C 15C - DM42, DM41X - WP34s Prime Soft. Lib |
|||
04-28-2016, 04:30 PM
(This post was last modified: 04-28-2016 04:31 PM by Spybot.)
Post: #11
|
|||
|
|||
RE: help with exact command. [Solved]
Yes definitely a nice program, it simulates very much what the [a b/c] key does, I'm sure it can be used in many programs.
Thank you for sharing. Spybot. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)