IP cmd

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

IP cmd

Message par compsystems » lun. déc. 24, 2018 3:45 am

Hi, BP
The following sequence of instructions, convert a periodic decimal number to its exact value 0.324532453245 = 3245/9999, I see something strange in the IP function (line 6), it must return 3245 and not 3244

iPart(3245) [enter] 3245.0
IP(3245) [enter] 3244 => 3245 (hpprime)
trunc(3245) [enter] 3245


Code : Tout sélectionner

1: autosimplify(0):;purge(f);
2: expr1:=(f=0.324532453245);
3: expr2:=expr1*10000;
4: expr3:=(expr2-expr1);
5: expr3:=simplify(expr3);
6: expr3:=(left(expr3)=IP(right(expr3)));
7: expr4:=expr3/9999;
8: expr4:=simplify(left(expr4))=(right(expr4));
9: approx(expr4)
10:right(expr1)
11:exact(right(expr1))
session Xcas

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: IP cmd

Message par parisse » lun. déc. 24, 2018 5:57 pm

That's rounding errors. Something displayed as 3245.0 may be 3244.999... and IP will return 3244. IP is discontinuous.

compsystems
Messages : 561
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: IP cmd

Message par compsystems » mar. déc. 25, 2018 3:30 pm

Why does iPart(3245) [enter] 3245.0 return with a decimal point?
I need a function that returns only the whole part

parisse
Messages : 5739
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: IP cmd

Message par parisse » mar. déc. 25, 2018 8:38 pm

Then use the right function, i.e. floor.

Répondre