frexp(n)

πŸ“¦ version 9.1.0, in nixpkgs unstable

✨ frexp(n) β€” Tcl Float Decomposition ✨

okay bestie, welcome to the frexp(n) page πŸ’– this one's a lil Tcl math girly and she's honestly so useful once you get her vibe.


🌸 NAME 🌸

frexp β€” split a floating-point number into fraction and exponent parts πŸŽ€

✨ SYNOPSIS ✨

package require tcl 9.1

frexp value

like, yes, she needs tcl 9.1 β€” no skipping that part, bestie 🫢

πŸ’… DESCRIPTION πŸ’…

so the frexp command takes a floating-point number, value, and hands you back a list of two values. yes, a list. two whole elements. slay.

  • the first element of the result is the fractional part of value β€” and she's signed, with a magnitude between 0.5 and 1.0
  • the second element of the result is the integer exponent from value

and literally when value is infinite, the fraction is also infinite, of the same sign πŸ”₯ no cap. that's just how she moves.

πŸ¦‹ EXAMPLE πŸ¦‹

the frexp command is paired with the ldexp function, like this:

set value 123.456
lassign [frexp $value] frac exp
set recovered [expr { ldexp($frac, $exp) }]
puts "$value -> $frac*2**$exp -> $recovered"
#       123.456 -> 0.9645*2**7 -> 123.456

the way that 123.456 comes back around to 123.456 β€” we love a full-circle moment πŸ˜­πŸ’–

πŸ‘‘ SEE ALSO πŸ‘‘

go read those too, iykyk πŸ’œ

🌈 KEYWORDS 🌈

floating point


and that's the tea πŸ“ this page is from Tcl, version 9.1, under the frexp(n) manual section β€” cute little math page, iconic behavior, periodt πŸ’…βœ¨

πŸ“¦ where this page comes from