
Why when I try cas.fround(34.567831,4) it always returns natural number?? What should I do to get decimal????
Posted 11 November 2005 - 10:56 AM
Posted 11 November 2005 - 11:09 AM
Posted 11 November 2005 - 11:44 AM
Edited by Orwell, 11 November 2005 - 11:48 AM.
Posted 11 November 2005 - 02:05 PM
Orwell, on Nov 11 2005, 02:44 PM, said:
Hmmm, Orwell it seems that you are quite busy indeed. You can convert a CAS result to a numerical value by treating it as a CAS function:There is no function to do that yet
But don't worry it will be available in the next releases
foo=cas.fround(34.567831,3)makes foo a "userdata" variable equal to 172839/5000, but
foo(0)is a "number" variable equal to 34.5678. You can even assign that variable to foo directly:
foo=cas.fround(34.567831,3)(0)will make foo a number variable.
Posted 11 November 2005 - 05:15 PM
Posted 11 November 2005 - 05:25 PM
Orwell, on Nov 11 2005, 08:15 PM, said:
Indeed, such a function will make things much clearer. "cas.evaluate" seems a very good name for this function. If I remeber well, Kilburn asked something similar to Tom's question a few days ago. It is currently not clear to most CPLua users that <CAS expression>(0) does the right thing.But I think that something like 'cas.tonumber' or 'cas.evaluate' would be better
Posted 12 November 2005 - 12:20 PM
PAP, on Nov 11 2005, 03:05 PM, said:
Hmmm, Orwell it seems that you are quite busy indeed. You can convert a CAS result to a numerical value by treating it as a CAS function:
foo=cas.fround(34.567831,3)makes foo a "userdata" variable equal to 172839/5000, butfoo(0)is a "number" variable equal to 34.5678. You can even assign that variable to foo directly:foo=cas.fround(34.567831,3)(0)will make foo a number variable.
In general, if foo is a CAS numerical result, it can be converted to a CPLua "number" variable by issuing foo(any number). It seems that this is a side-effect of the way that CAS functions can be used in CPLua, but it works, provided that the CAS result is not in exponential form (see my bug report for that).
Posted 12 November 2005 - 05:18 PM
Posted 12 November 2005 - 06:27 PM
Orwell, on Nov 12 2005, 08:18 PM, said:
Nooo, I didn't said that solving bugs is a pleasure. I said that I like solving programming problems, not bugsCool, now I can introduce any bug I want since it will be a pleasure to solve them
Posted 16 November 2005 - 07:51 PM
x = cas("45/7") x2 = x()will create a number 'x2' with value 6.428...
Posted 16 November 2005 - 08:18 PM
Orwell, on Nov 16 2005, 09:51 PM, said:
Short, clear, functional. I like it. But what if you add a fake number anyway? For example, if you forgot to remove a zero (or any other number), needed in previous versions?In the next CPLua version it will be possible to evaluate CAS expressions (to convert them into a simple number) in the same way, but without having to give a fake "zero" value in the parenthesis.
Thus,x = cas("45/7") x2 = x()will create a number 'x2' with value 6.428...
Posted 16 November 2005 - 08:35 PM
0 members, 1 guests, 0 anonymous users