Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0f33083001
Fetching contributors…

Cannot retrieve contributors at this time

97 lines (81 sloc) 2.866 kb
/*
* Copyright (C) 2001-2009, The Parrot Foundation.
*/
#include "pmc/pmc_integer.h"
#include "pmc/pmc_string.h"
static INTVAL dynpmc_TclInt;
static INTVAL dynpmc_TclString;
pmclass TclFloat
dynpmc auto_attrs
extends Float
does float
group tcl_group
hll tcl
maps Float
{
VTABLE void class_init() {
dynpmc_TclInt = Parrot_pmc_get_type_str(INTERP, CONST_STRING(INTERP, "TclInt"));
dynpmc_TclString = Parrot_pmc_get_type_str(INTERP, CONST_STRING(INTERP, "TclString"));
}
VTABLE void set_integer_native(INTVAL value) {
Parrot_pmc_reuse(INTERP, SELF, dynpmc_TclInt, 0);
SETATTR_Integer_iv(INTERP, SELF, value);
}
VTABLE void set_string_native(STRING *value) {
Parrot_pmc_reuse(INTERP, SELF, dynpmc_TclString, 0);
SETATTR_String_str_val(INTERP, SELF, Parrot_str_copy(INTERP, value));
}
VTABLE STRING* get_string() {
UINTVAL buflen;
int check_flag;
STRING *buff;
STRING *dot;
STRING *e;
STRING *dot_zero;
STRING *_precision = CONST_STRING(INTERP, "$tcl_precision");
STRING *_tcl = CONST_STRING(INTERP, "tcl");
PMC * const root_ns = INTERP->root_namespace;
PMC * const hll_ns = VTABLE_get_pmc_keyed_str(INTERP, root_ns, _tcl);
PMC * precision_pmc =
Parrot_ns_find_global_from_op(INTERP, hll_ns, _precision, NULL);
INTVAL precision = VTABLE_get_integer(INTERP, precision_pmc);
if (precision == 0)
precision = 16; /* RT#40639: hack to approximate right output.*/
buff = Parrot_sprintf_c(INTERP, "%.*vg", precision, SELF.get_number());
/*
* this sprintf variant will return something that looks like
* an int if it can : if we have no decimal point then tack on
* on and return
*/
dot = CONST_STRING(INTERP, ".");
e = CONST_STRING(INTERP, "e");
if (Parrot_str_find_index(INTERP, buff, dot, 0) == -1
&& Parrot_str_find_index(INTERP, buff, e, 0) == -1
&& ! Parrot_str_equal(INTERP, CONST_STRING(INTERP, "NaN"),buff)) {
dot_zero = CONST_STRING(INTERP, ".0");
buff = Parrot_str_concat(INTERP, buff, dot_zero);
return buff;
}
check_flag = 0;
buflen = Parrot_str_length(INTERP, buff);
while (buflen) {
if (Parrot_str_indexed(INTERP, buff, buflen-1) == '0') {
buflen--;
check_flag = 1;
}
else {
break;
}
}
/* truncate the string */
buff->strlen = buflen;
buff->bufused = buflen;
return buff;
}
}
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/
Jump to Line
Something went wrong with that request. Please try again.