Menu

Signed

Nicolas Hainaux

Signed objects are the ones that have a + or - sign.
This is the case of all Evaluable objects.

Most of the time, the sign is at the beginning of the object and, for Exponenteds, is not embraced by the exponent. But it is not always the case : Sums and Products for instance, do not have their own sign. The sign that is used is the one of their first element. This might change to simplify the code, if we find a solution that gives satisfying results.

Fields Methods (provided) Methods (must be reimplemented)
sign get_sign() get_minus_signs_nb()
set_sign()
set_opposite_sign()
is_negative()
is_positive()

set_opposite_sign() will just change the sign of the object to its contrary
get_minus_signs_nb() is essentially an auxiliary method to help maths_lib.sign_of_product() to determine the sign of a given Product. It was more practical to give a get_minus_signs_nb() to each object to return recursively the number of its minus signs, than counting them in a loop.

For instance, if the object is : -4x(-8x - 1)×(+3)×(-a) get_minus_signs_nb() should return :
-4x -> 1
(-8x - 1) -> 0
(+3) -> 0
(-a) -> 1
So for the complete object, an total of 2 minus signs.
If this Product needs to be reduced, the final sign will hence be '+'.

Check Signed's complete doc

Back


Related

Doc for dev: Core Objects

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.