modf

modf(x)

Return a tuple (fpart,ipart) of the fractional and integral parts of a number. Both parts have the same sign as the argument.

Examples

  1. Extract fractional and integral parts of a number:

    julia> modf(3.75)
    (0.75, 3.0)

    This example returns a tuple containing the fractional part (0.75) and the integral part (3.0) of the number 3.75.

  2. Handle negative numbers:

    julia> modf(-2.25)
    (-0.25, -2.0)

    It correctly handles negative numbers, returning the fractional part (-0.25) and the integral part (-2.0) with the same sign as the argument.

  3. Modf with integers:
    julia> modf(10)
    (0.0, 10.0)

    When an integer is provided, the fractional part is always 0.0, and the integral part is the same as the input.

Common mistake example:

julia> modf("hello")
ERROR: MethodError: no method matching modf(::String)

In this example, modf is called with a string argument, which is not a valid input type. Make sure to provide numeric values to the modf function.

See Also

abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: