Tcl_PrintDouble(3)

πŸ“¦
version 9.0.3 Β· 3 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

✨ 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 represents value. and listen, this has to have at least TCL_DOUBLE_SPACE characters 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