Decimal Functions in Python- Set 2:

We have already discussed some functions in Set 1; now we will further discuss these functions.

  1. logical_and(): It is a function that computes the digit wise logical ‘and’ operation of the number. The digits can have values 0 or 1 only.
  2. logical_or(): It is a function that computes digit wise, logical ‘or’ operation of number. The digits can have values 0 or 1 only.
  3. logical_xor(): It is a function that computes the digit wise, logical ‘xor’ operation of the number. The digits can have values 0 or 1 only.
  4. logical_invert(): It is a function that computes the digit wise logical ‘and’ operation of the number. The digits can have values 0 or 1 only.

  5. next_plus(): It is a function that returns the smallest number which can be represented, larger than the given number.
  6. next_minus(): It is a function that returns the largest number which can be represented, smaller than given number.

  7. Next_toward(): It is a function that returns the number which is nearest to the first argument in the direction of second argument. When both the numbers are equal, it returns the second number along with the sign of first number.
  8. normalize(): It is a function that prints the number after erasing all the rightmost trailing zeroes in the number.

  9. quantize(): It is a function that returns the first argument with number of digits in decimal part(exponent) shortened by number of digits in decimal part of second argument.
  10. same_quantum(): It is a function that returns 0 in case both the numbers have different exponent, and 1 in case both the numbers have same exponent.

  11. rotate(): It is a function that rotates the first argument by amount mentioned in second argument. In case the sign of second argument is positive, the rotation is towards left; for other cases, the rotation is towards right. The sign of the first argument is not changed.
  12. shift(): It is a function that shifts the first argument by the amount which is mentioned in second argument. If sign of second argument is positive, shifting is towards left, in other cases shifting is towards right. The sign of first argument is not changed. The shifted digits are replaced by 0.
  13. remainder_near(): It will return the value “1st – (n*2nd)” where n is integer value nearest to the result of 1st value/2nd value. If both the integers have same proximity even then one is chosen.
  14. scaleb(): It is a function that shifts the exponent of 1st number by value of second argument.

 

Leave a Reply

Your email address will not be published. Required fields are marked *