frexp(n)
β¨ 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 between0.5and1.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
- 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