Syntax Python: x // y floored quotient of x and y

Messages in english

Modérateur : xcasadmin

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

Syntax Python: x // y floored quotient of x and y

Message par compsystems » sam. févr. 16, 2019 10:01 pm

Hello, I am testing the syntax of python on xcas

According to https://docs.python.org/3.7/library/std ... pesnumeric

Says
Also referred to as integer division. The resultant value is a whole integer, though the result’s type is not necessarily int. The result is always rounded towards minus infinity: 1//2 is 0, (-1)//2 is -1, 1//(-2) is -1, and (-1)//(-2) is 0.

xcas have to emulate floored quotient =)

https://en.wikipedia.org/wiki/Modulo_operation

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

Re: Syntax Python: x // y floored quotient of x and y

Message par parisse » lun. févr. 18, 2019 4:41 pm

It does in Python compat mode, at least for positive values of b (I don't really care of negative values of b).

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

Re: Syntax Python: x // y floored quotient of x and y

Message par compsystems » lun. févr. 18, 2019 8:19 pm

// is interpreted as iquo cmd,

I think it is important to define a new function flooredMod() on xCAS, which include negative values of b and decimal numbers

pyhton
-5.5//3 returns -2


PD: to emulate output, on the xor operator
Python:
True^True returns False
Xcas Syntax Python
python_compat(2) and (^==Xor)
True^True returns 0 => false =)

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

Re: Syntax Python: x // y floored quotient of x and y

Message par parisse » mar. févr. 19, 2019 8:12 am

fmod(a,b) returns a mod b for floats.

Répondre