modf(n)

πŸ“¦ version 9.1.0, in nixpkgs unstable

πŸ’– 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