diff --git a/ivy/functional/ivy/experimental/elementwise.py b/ivy/functional/ivy/experimental/elementwise.py index f37a875970fb0..3a0f0e12cadb8 100644 --- a/ivy/functional/ivy/experimental/elementwise.py +++ b/ivy/functional/ivy/experimental/elementwise.py @@ -1135,3 +1135,39 @@ def frexp( (ivy.array([0.5, 0.5, 0.75]), ivy.array([1, 2, 2])) """ return ivy.current_backend(x).frexp(x, out=out) + + +@handle_exceptions +@handle_nestable +@handle_array_like_without_promotion +@handle_out_argument +@to_native_arrays_and_back +def modf( + x: Union[ivy.Array, ivy.NativeArray], + /, + *, + out: Optional[Tuple[ivy.Array, ivy.Array]] = None, +) -> Tuple[ivy.Array, ivy.Array]: + """ + Decompose the elements of x into fractional and integral parts. + + Parameters + ---------- + x + Input array. + out + Optional output array for writing the result to. + It must have a shape that the inputs broadcast to. + + Returns + ------- + ret + A tuple of two arrays, the fractional and integral parts. + + Examples + -------- + >>> x = ivy.array([1.5, 2.7, 3.9]) + >>> ivy.modf(x) + (ivy.array([0.5, 0.7, 0.9]), ivy.array([1, 2, 3])) + """ + return ivy.current_backend(x).modf(x, out=out)