modf function - python math module

The modf function math function in python returns the integer and fractional portions of a number as a tuple of floating point numbers

Math Updated 25 Sep 2016 1 min read

Method Name

modf(aNumber_in)

Method Overview

  • modf() function of math module in python returns the integer and the fractional parts as a tuple.

  • The modf() function returns both the integer and the fractional parts
    with the same sign as the parameter.

  • Both integer and the fractional parts are of type floating point number

Example

python
import math

# Get the integer and fractional values for Rayleigh factor

RayleighFactor   =  1.2196698912

RayleighTuple    = math.modf(RayleighFactor)

print("Printing RayleighFactor as a tuple in python... integer first and fraction next")

print(RayleighTuple)

# Truncate Constant of Theodorus

ConstantofTheodorus = 1.7320508075

TheodorusTuple      = math.modf(ConstantofTheodorus)

print("Printing Theodorus Constant as tuple in python...integer first and fraction next")

print(TheodorusTuple)

Output

Output
Printing RayleighFactor as a tuple in python... integer first and fraction next

(0.2196698911999999, 1.0)

Printing Theodorus Constant as tuple in python...integer first and fraction next

(0.7320508075000001, 1.0)