Intrinsics1 min read
modf
Splits a floating-point value into fractional and whole parts.
Reading Time
1 min
Word Count
77
Sections
7
Try It Live
Test modf in a live shader
Open the playground, start from a visual preset, and wire modf into the fragment stage to see how it behaves with real values.
Open PlaygroundThe modf function separates a float into its fractional and whole-number parts. It returns a BwslModfResult struct with fraction and whole fields.
Live Demo
Signature
bwsl
modf :: (float x) -> BwslModfResult
bwsl
struct BwslModfResult {
fraction: float
whole: float
}
Parameters
| Parameter | Type | Description |
|---|---|---|
x | float | Value to split |
Return Value
Returns BwslModfResult, where fraction contains the fractional component and whole contains the whole-number component.
Example
bwsl
float wrapped = modf(value).fraction;
float cell = modf(value).whole;Compiled Output
When compiled to GLSL:
glsl
modf(x, whole)