fpclassify(n)
π fpclassify(n) β the Tcl Float Classifier π
okay bestie, so this little cutie lives in the n section of the Tcl manual, and it's literally called the Tcl Float Classifier. We're talking Tcl 9.0 energy. She's small, she's precise, she's the friend who tells you exactly what kind of weird your number is. π¦
β¨ NAME β¨
fpclassify β Floating point number classification of Tcl values
πΈ SYNOPSIS πΈ
package require tcl 9.0
fpclassify value
π DESCRIPTION π
So here's the tea: fpclassify takes a floating point number, value, and hands you back one of these strings describing what kind of float it is. Not a vibe check β a number check. π
zeroβvalueis a floating point zero.subnormalβvalueis the result of a gradual underflow. (π the precision loss era)normalβvalueis an ordinary floating-point number. Not zero, not subnormal, not infinite, not NaN. Just a chill, well-adjusted float. β¨infiniteβvalueis a floating-point infinity.nanβvalueis Not-a-Number. π
heads up bestie:fpclassifythrows an error ifvalueis not a floating-point value and can't be converted into one. She does not play about that. π
π₯ EXAMPLE π₯
Here's how you check whether the result of a computation is numerically safe or not. (note: this does not guard against numerical errors β it only guards against representational problems. iykyk.)
set value [command-that-computes-a-value]
switch [fpclassify $value] {
normal - zero {
puts "Result is $value"
}
infinite {
puts "Result is infinite"
}
subnormal {
puts "Result is $value - WARNING! precision lost"
}
nan {
puts "Computation completely failed"
}
}
the subnormal branch screaming "WARNING! precision lost" is so real, honestly. π«Ά
π SEE ALSO π
β KEYWORDS β
- floating point
π STANDARDS π
This command depends on the fpclassify() C macro conforming to βISO C99β (i.e., to ISO/IEC 9899:1999). yes she's standards-compliant, she's got her life together. π
π COPYRIGHT π
Copyright Β© 2018 Kevin B. Kenny <kennykb@acm.org>. All rights reserved
and that's the whole page bestie, no cap. π this diva shipped with Tcl 9.0 (that's the version stamped on the page, front and back) β mwah, periodt. π β¨
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- Copyright (c) 2018 Kevin B. Kenny <kennykb@acm.org>. All rights reserved
- Copyright (c) 2019 Donal Fellows
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms