Tcl_DoubleObj(3tcl)
π Tcl_DoubleObj β the double-precision era π
okay bestie, this is Tcl_DoubleObj(3tcl) from the Tcl Library Procedures, and it's literally the whole tutorial on how to make, poke at, and read Tcl values that are holding floating-point (double-precision) numbers. it's giving β¨math girlieβ¨ and honestly? iconic.
β¨ NAME β¨
Tcl_NewDoubleObj, Tcl_SetDoubleObj, Tcl_GetDoubleFromObj β manipulate Tcl values as floating-point values π«Ά
πΈ SYNOPSIS πΈ
#include <tcl.h>
Tcl_Obj *
Tcl_NewDoubleObj(doubleValue)
Tcl_SetDoubleObj(objPtr, doubleValue)
int
Tcl_GetDoubleFromObj(interp, objPtr, doublePtr)
π ARGUMENTS π
double doubleValue(in) β a double-precision floating-point value that's used to initialize or set a Tcl value. it's the number you're bringing to the party πTcl_Obj *objPtr(in/out) β forTcl_SetDoubleObj, this points to the value you're storing a double into. forTcl_GetDoubleFromObj, this refers to the value you're retrieving a double from. so it's the same pointer, different direction of vibes πTcl_Interp *interp(in/out) β when it's non-NULL, an error message gets dropped here when double value retrieval fails. so if things go wrong, she's the one holding the receipts πdouble *doublePtr(out) β points to the place where the double value obtained fromobjPtrgets stored. it's the lil landing pad π¬
π DESCRIPTION π
these procedures are your whole toolkit for creating, modifying, and reading Tcl values that hold double-precision floating-point values. three besties, three jobs, no cap.
Tcl_NewDoubleObj creates and returns a brand new Tcl value initialized to the double value doubleValue. the returned Tcl value is unshared β it's fresh out the box, nobody else is holding it, main character energy only π
Tcl_SetDoubleObj sets the value of an existing Tcl value pointed to by objPtr to the double value doubleValue. but β and listen carefully bestie β the objPtr argument must point to an unshared Tcl value. any attempt to set the value of a shared Tcl value violates Tcl's copy-on-write policy. π¨ not a vibe, don't do it. and also, any existing string representation or internal representation in that unshared Tcl value will be freed as a consequence of setting the new value. like, gone. released. the old rep does not get to stay π
Tcl_GetDoubleFromObj attempts to retrieve a double value from the Tcl value objPtr. if the attempt succeeds, then TCL_OK is returned, and the double value is written to the storage pointed to by doublePtr β¨ success slay. if the attempt fails, then TCL_ERROR is returned, and if interp is non-NULL, an error message is left in interp π also, heads up: the Tcl_ObjType of objPtr may be changed, which makes subsequent calls to Tcl_GetDoubleFromObj more efficient. glow-up for future you π¦
π REFERENCE COUNT MANAGEMENT π
this is the part where we count our blessings (and our references) π
Tcl_NewDoubleObjalways returns a zero-reference object, much likeTcl_NewObj. baby starts at zero, that's just how she arrives πΌTcl_SetDoubleObjdoes not modify the reference count of itsobjPtrargument, but it does require that the object be unshared. so like, don't touch the count, but do make sure nobody else is holding it πTcl_GetDoubleFromObjdoes not modify the reference count of itsobjPtrargument; it only reads. it's just looking respectfully π note however that this function may set the interpreter result; if that is the only place that is holding a reference to the object, it will be deleted. yes, really. read-only doesn't mean the object is safe forever, bestie, keep an eye on it π
π SEE ALSO π
Tcl_NewObj, Tcl_DecrRefCount, Tcl_IncrRefCount, Tcl_GetObjResult β go read those next, they're the extended universe π
β KEYWORDS β
double, double value, double type, internal representation, value, value type, string representation
and that's the whole page, no notes π this one shipped with Tcl 8.0, and it lives at Tcl_DoubleObj(3tcl) β so when you're deep in the C API at 3am and everything is doubles, you know exactly where to find me. mwah, go write some unshared objects πβ¨π«Ά
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1996-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms