MODF(3P)
πΈ MODF(3P) β the POSIX Programmer's Manual page, bestie edition πΈ
okay so before we even start, hi, hello, welcome to the POSIX Programmer's Manual π this page lives in the 3P section, and it's about modf, modff and modfl. grab a snack, we're doing floating-point decomposition and it's actually kind of iconic.
π¨ PROLOG π¨
okay so real talk first: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β so if you're on Linux, pls pls pls go consult the corresponding Linux manual page for the tea on Linux behavior π«Ά. also possible: the interface just isn't implemented on Linux at all. not me warning you before you even get to the fun part π.
β¨ NAME β¨
modf, modff, modfl β decompose a floating-point number π¦
like. it splits a float into its two vibes. that's the whole job. slay.
π SYNOPSIS π
#include <math.h>
double modf(double x, double *iptr);
float modff(float value, float *iptr);
long double modfl(long double value, long double *iptr);
yes bestie, three of them, one for each flavour of float. they're a set. they come as a trio. periodt π
π DESCRIPTION π
okay so first thing's first: the functionality described on this reference page is aligned with the ISO C standard. if there's any conflict between the requirements described here and the ISO C standard, that conflict is unintentional β nobody meant it, it's not a beef, it's a typo situation. and this volume of POSIX.1β2017 defers to the ISO C standard. so like, ISO C is the main character here and we're just supporting cast β¨.
now the actual function, which is lowkey elegant:
these functions shall break the argument x into integral and fractional parts, and here's the cute part β each of which has the same sign as the argument. so if you hand it a negative, both halves come back negative. no sign-flipping jumpscares. we love consistency.
then it stores the integral part in the object pointed to by iptr, and the type of that integral part depends on which sibling you called:
- for the
modf()function, it's stored as adouble - for the
modff()function, it's stored as afloat - for the
modfl()function, it's stored as along double
so the fractional part comes back as the return value, and the integral part gets yeeted into *iptr. two-for-one. it's giving efficiency π.
π«Ά RETURN VALUE π«Ά
upon successful completion, these functions shall return the signed fractional part of x. signed!! remember the sign thing. it matters.
and now the special cases, because floats always have special cases, they can never just be normal:
- if
xisNaN, aNaNshall be returned, and*iptrshall be set to aNaN. so like, both slots get NaN'd. no escape π - if
xisΒ±Inf,Β±0shall be returned, and*iptrshall be set toΒ±Inf. so the infinity part goes into the integral slot where it belongs (it IS the integral part, fr fr) and you get a signed zero back as the fraction. infinity has no fractional bits, it said "not today" π
π ERRORS π
no errors are defined. none. zero. she doesn't do errors. she's unbothered, moisturized, in her lane, focused, flourishing β¨.
heads up tho: the following sections are informative. they're like, lore. background. not requirements. iykyk.
π EXAMPLES π
None.
literally none. there are no examples. we're rawdogging this documentation. okay!! π
π§ APPLICATION USAGE π§
here's the cute little relationship the modf() function maintains β it computes the function result and *iptr such that:
a = modf(x, iptr) ;
x == a+*iptr ;
see how it all adds back up?? the two pieces reassemble into the original. it's giving "we complete each other" π₯Ή
β¦but, and this is important, that's allowing for the usual floating-point inaccuracies. so like. approximately. don't come for me with a bit-for-bit comparison, bestie, floats are famously messy πΈ.
π RATIONALE π
None.
no rationale. no justification. it simply is. iconic behavior honestly π
β FUTURE DIRECTIONS β
None.
the future is undefined but this function is not changing. she's perfect as she is π
π₯ SEE ALSO π₯
frexp()isnan()ldexp()
and also, from the Base Definitions volume of POSIX.1β2017: <math.h> π
go read those next, bestie, they're the friend group.
π COPYRIGHT π
okay so legally I have to say this exactly and I'm gonna say it with love:
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page!! π this one came to you courtesy of IEEE/The Open Group, 2017, and yes the footer really does just say MODF(3P) at the bottom like a little signature. mwah. go decompose something. you got this π¦β¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms