2 * Copyright (C) 2001-2003, The Perl Foundation.
6 * These are the vtable functions for the TclFloat base class
7 * Data Structure and Algorithms:
13 #include "parrot/embed.h"
26 STRING* get_string() {
33 STRING *_precision = string_from_cstring(INTERP, "$tcl_precision", 14);
34 STRING *_tcl = string_from_cstring(INTERP, "tcl", 3);
36 PMC * const root_ns = INTERP->root_namespace;
37 PMC * const hll_ns = VTABLE_get_pmc_keyed_str(INTERP, root_ns, _tcl);
39 Parrot_find_global_op(INTERP, hll_ns, _precision, NULL);
40 INTVAL precision = VTABLE_get_integer(INTERP, precision_pmc);
43 precision = 16; /* RT#40639: hack to approximate right output.*/
45 buff = Parrot_sprintf_c(INTERP, "%.*vg", precision, PMC_num_val(SELF));
48 * this sprintf variant will return something that looks like
49 * an int if it can : if we have no decimal point then tack on
52 dot = string_from_cstring(INTERP, ".", 1);
53 e = string_from_cstring(INTERP, "e", 1);
55 if (string_str_index(INTERP, buff, dot, 0) == -1
56 && string_str_index(INTERP, buff, e, 0) == -1) {
57 dot_zero = string_from_cstring(INTERP, ".0", 2);
58 buff = string_append(INTERP, buff, dot_zero);
63 buflen = string_length(INTERP, buff);
65 if (string_index(INTERP, buff, buflen-1) == '0') {
74 /* truncate the string */
75 buff->strlen = buflen;
76 buff->bufused = buflen;
84 * c-file-style: "parrot"
86 * vim: expandtab shiftwidth=4: