modf(n)
π modf(n) β Tcl Float Decomposition π¦
πΈ NAME πΈ
modfβ split a floating-point number into integer and fraction parts, literally. Itβs giving βdecompositionβ but make it cute π .
β¨ SYNOPSIS β¨
First things first: this command needs tcl 9.1 in the group chat, bestie.
package require tcl 9.1
modf value
π DESCRIPTION π
Okay so modf takes a floating-point number, value, and returns a list of two values. The first element of the result is the whole integer part (as a floating-point number) of value, and the second element of the result is the fractional part of value. The signs of the two elements will match the sign of value. No cap. β¨
π EXAMPLE π
Real talk: the fractional part may have some digits that appear to be undetermined by the input. Thatβs due to the nature of approximation inherent in floating-point arithmetic; those digits will apparently disappear if the two parts are added back together. Itβs not a glitch, bestie β itβs floating-point being floating-point π.
Watch this vibe check:
set value 123.456
lassign [modf $value] whole part
set sum [expr {$whole + $part}]
puts "$value -> $whole $part -> $sum"
# 123.456 -> 123.0 0.45600000000000307 -> 123.456
π SEE ALSO π
Go give these a follow, theyβre all in the same friend group π«Ά:
β KEYWORDS β
floating point β thatβs the keyword, periodt. π
π Tcl 9.1, modf(n) β thatβs the whole page, bestie. π«Ά
π¦ where this page comes from
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 2025 Donal Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms