Tcl_PrintDouble(3)
β¨ Tcl_PrintDouble β the Tcl Library Procedures glow-up β¨
okay bestie, gather round, we're doing a lil float-to-string moment π this one lives in the Tcl library procedures lineup and it's short, sweet, and honestly iconic.
πΈ NAME πΈ
Tcl_PrintDouble β literally just convert a floating value into a string, no cap π¦
π SYNOPSIS π
#include <tcl.h>
Tcl_PrintDouble(interp, value, dst)
π ARGUMENTS π
Tcl_Interp *interp(in) β bestie... this one is ignored. fully. she's just there for the vibes πdouble value(in) β the floating-point value that's getting converted, the main character of this whole operation πchar *dst(out) β where we store the string that representsvalue. and listen, this has to have at leastTCL_DOUBLE_SPACEcharacters of storage. do not skimp on the space, she will overflow and you will cry π
π DESCRIPTION π
okay so Tcl_PrintDouble generates a string that represents the value of value and stores it in memory at the location given by dst. easy enough, right? π
it uses %g format to generate that string, but with one lil special twist: the string is guaranteed to contain either a . or an e so that it doesn't look like an integer. like, imagine a float showing up to the party dressed as an int... not on her watch. so wherever %g would generate an integer with no decimal point, Tcl_PrintDouble just adds .0 and suddenly she's serving float, periodt β¨
and the way that the result has the fewest digits needed to represent the number, in such a way that Tcl_NewDoubleObj will generate the same number when it's presented with the given string?? that's efficiency, that's precision, that's chef's kiss π§ IEEE semantics of rounding to even apply to the conversion, iykyk π
β KEYWORDS β
conversion, double-precision, floating-point, string
and that's the whole page, bestie π«Ά this one's from the Tcl 8.0 era of the Tcl library procedures β take care of her, she rounds to even and she knows it π π
π¦ 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
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 1989-1993 The Regents of the University of California
- Copyright (c) 1994-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms