diff --git a/libkc3/buf_inspect.c b/libkc3/buf_inspect.c
index a72179c..4c6ee24 100644
--- a/libkc3/buf_inspect.c
+++ b/libkc3/buf_inspect.c
@@ -1938,7 +1938,7 @@ sw buf_inspect_f128_size (s_pretty *pretty, const f128 *x)
return r;
result += r;
}
- if ((r = buf_inspect_s64_size(pretty, &exp)) <= 0)
+ if ((r = buf_inspect_s64_decimal_size(pretty, &exp)) <= 0)
return r;
result += r;
}
diff --git a/libkc3/s.c.in b/libkc3/s.c.in
index 9e13162..70d4a33 100644
--- a/libkc3/s.c.in
+++ b/libkc3/s.c.in
@@ -71,9 +71,7 @@ s_bits$ * s_bits$_init_cast
*s = (s_bits$) tag->data.s8;
return s;
case TAG_STR:
- if (! s_bits$_init_str(s, &tag->data.str))
- return NULL;
- return s;
+ return s_bits$_init_str(s, &tag->data.str);
case TAG_U8:
*s = (s_bits$) tag->data.u8;
return s;
diff --git a/libkc3/s16.c b/libkc3/s16.c
index d3339ca..37f1caf 100644
--- a/libkc3/s16.c
+++ b/libkc3/s16.c
@@ -71,9 +71,7 @@ s16 * s16_init_cast
*s = (s16) tag->data.s8;
return s;
case TAG_STR:
- if (! s16_init_str(s, &tag->data.str))
- return NULL;
- return s;
+ return s16_init_str(s, &tag->data.str);
case TAG_U8:
*s = (s16) tag->data.u8;
return s;
diff --git a/libkc3/s32.c b/libkc3/s32.c
index ce50e80..9f6426a 100644
--- a/libkc3/s32.c
+++ b/libkc3/s32.c
@@ -71,9 +71,7 @@ s32 * s32_init_cast
*s = (s32) tag->data.s8;
return s;
case TAG_STR:
- if (! s32_init_str(s, &tag->data.str))
- return NULL;
- return s;
+ return s32_init_str(s, &tag->data.str);
case TAG_U8:
*s = (s32) tag->data.u8;
return s;
diff --git a/libkc3/s64.c b/libkc3/s64.c
index 24ac7d2..dde01ae 100644
--- a/libkc3/s64.c
+++ b/libkc3/s64.c
@@ -71,9 +71,7 @@ s64 * s64_init_cast
*s = (s64) tag->data.s8;
return s;
case TAG_STR:
- if (! s64_init_str(s, &tag->data.str))
- return NULL;
- return s;
+ return s64_init_str(s, &tag->data.str);
case TAG_U8:
*s = (s64) tag->data.u8;
return s;
diff --git a/libkc3/s8.c b/libkc3/s8.c
index 29e7fad..3b7c008 100644
--- a/libkc3/s8.c
+++ b/libkc3/s8.c
@@ -71,9 +71,7 @@ s8 * s8_init_cast
*s = (s8) tag->data.s8;
return s;
case TAG_STR:
- if (! s8_init_str(s, &tag->data.str))
- return NULL;
- return s;
+ return s8_init_str(s, &tag->data.str);
case TAG_U8:
*s = (s8) tag->data.u8;
return s;
diff --git a/libkc3/str.c b/libkc3/str.c
index 74903d2..8705bd3 100644
--- a/libkc3/str.c
+++ b/libkc3/str.c
@@ -373,6 +373,12 @@ s_str * str_init_cast (s_str *str, const s_sym * const *type,
return str_init_callable(str, tag->data.callable);
case TAG_CHARACTER:
return str_init_character(str, tag->data.character);
+ case TAG_F32:
+ return str_init_f32(str, tag->data.f32);
+ case TAG_F64:
+ return str_init_f64(str, tag->data.f64);
+ case TAG_F128:
+ return str_init_f128(str, tag->data.f128);
case TAG_IDENT:
return str_init_ident(str, &tag->data.ident);
case TAG_LIST:
@@ -555,6 +561,189 @@ s_str * str_init_f (s_str *str, const char *fmt, ...)
return str;
}
+s_str * str_init_f32 (s_str *str, f32 x)
+{
+ char a[32];
+ s_buf buf;
+ s64 exp;
+ u8 i;
+ u8 j;
+ sw r;
+ buf_init(&buf, false, sizeof(a), a);
+ exp = 0.0;
+ if (x == 0.0) {
+ if ((r = buf_write_1(&buf, "0.0")) < 0)
+ return NULL;
+ goto ok;
+ }
+ if (x < 0) {
+ if ((r = buf_write_1(&buf, "-")) <= 0)
+ return NULL;
+ x = -x;
+ }
+ if (x >= 1.0)
+ while (x >= 10.0) {
+ x /= 10.0;
+ exp++;
+ }
+ else
+ while (x < 1.0) {
+ x *= 10.0;
+ exp--;
+ }
+ i = (u8) x;
+ x -= i;
+ i += '0';
+ if ((r = buf_write_character_utf8(&buf, i)) <= 0)
+ return NULL;
+ if ((r = buf_write_1(&buf, ".")) <= 0)
+ return NULL;
+ j = 6;
+ do {
+ x *= 10;
+ i = (u8) x;
+ x -= i;
+ i += '0';
+ if ((r = buf_write_character_utf8(&buf, i)) <= 0)
+ return NULL;
+ j--;
+ } while (x > pow(0.1, j) && j);
+ if (exp) {
+ if ((r = buf_write_1(&buf, "e")) <= 0)
+ return NULL;
+ if (exp > 0) {
+ if ((r = buf_write_1(&buf, "+")) <= 0)
+ return NULL;
+ }
+ if ((r = buf_inspect_s64_decimal(&buf, &exp)) <= 0)
+ return NULL;
+ }
+ ok:
+ return buf_read_to_str(&buf, str);
+}
+
+s_str * str_init_f64 (s_str *str, f64 x)
+{
+ char a[32];
+ s_buf buf;
+ s64 exp;
+ u8 i;
+ u8 j;
+ sw r;
+ buf_init(&buf, false, sizeof(a), a);
+ exp = 0.0;
+ if (x == 0.0) {
+ if ((r = buf_write_1(&buf, "0.0")) < 0)
+ return NULL;
+ goto ok;
+ }
+ if (x < 0) {
+ if ((r = buf_write_1(&buf, "-")) <= 0)
+ return NULL;
+ x = -x;
+ }
+ if (x >= 1.0)
+ while (x >= 10.0) {
+ x /= 10.0;
+ exp++;
+ }
+ else
+ while (x < 1.0) {
+ x *= 10.0;
+ exp--;
+ }
+ i = (u8) x;
+ x -= i;
+ i += '0';
+ if ((r = buf_write_character_utf8(&buf, i)) <= 0)
+ return NULL;
+ if ((r = buf_write_1(&buf, ".")) <= 0)
+ return NULL;
+ j = 14;
+ do {
+ x *= 10;
+ i = (u8) x;
+ x -= i;
+ i += '0';
+ if ((r = buf_write_character_utf8(&buf, i)) <= 0)
+ return NULL;
+ j--;
+ } while (x > pow(0.1, j) && j);
+ if (exp) {
+ if ((r = buf_write_1(&buf, "e")) <= 0)
+ return NULL;
+ if (exp > 0) {
+ if ((r = buf_write_1(&buf, "+")) <= 0)
+ return NULL;
+ }
+ if ((r = buf_inspect_s64_decimal(&buf, &exp)) <= 0)
+ return NULL;
+ }
+ ok:
+ return buf_read_to_str(&buf, str);
+}
+
+s_str * str_init_f128 (s_str *str, f128 x)
+{
+ char a[128];
+ s_buf buf;
+ s64 exp;
+ u8 i;
+ u8 j;
+ sw r;
+ buf_init(&buf, false, sizeof(a), a);
+ exp = 0.0;
+ if (x == 0.0) {
+ if ((r = buf_write_1(&buf, "0.0")) < 0)
+ return NULL;
+ goto ok;
+ }
+ if (x < 0) {
+ if ((r = buf_write_1(&buf, "-")) <= 0)
+ return NULL;
+ x = -x;
+ }
+ if (x >= 1.0)
+ while (x >= 10.0) {
+ x /= 10.0;
+ exp++;
+ }
+ else
+ while (x < 1.0) {
+ x *= 10.0;
+ exp--;
+ }
+ i = (u8) x;
+ x -= i;
+ i += '0';
+ if ((r = buf_write_character_utf8(&buf, i)) <= 0)
+ return NULL;
+ if ((r = buf_write_1(&buf, ".")) <= 0)
+ return NULL;
+ j = 33;
+ do {
+ x *= 10;
+ i = (u8) x;
+ x -= i;
+ i += '0';
+ if ((r = buf_write_character_utf8(&buf, i)) <= 0)
+ return NULL;
+ j--;
+ } while (x > pow(0.1, j) && j);
+ if (exp) {
+ if ((r = buf_write_1(&buf, "e")) <= 0)
+ return NULL;
+ if (exp > 0) {
+ if ((r = buf_write_1(&buf, "+")) <= 0)
+ return NULL;
+ }
+ if ((r = buf_inspect_s64_decimal(&buf, &exp)) <= 0)
+ return NULL;
+ }
+ ok:
+ return buf_read_to_str(&buf, str);
+}
+
DEF_STR_INIT_STRUCT(fn)
s_str * str_init_ftime (s_str *str, s_time *time, const s_str *format)
diff --git a/libkc3/sw.c b/libkc3/sw.c
index 38ba225..ed966fa 100644
--- a/libkc3/sw.c
+++ b/libkc3/sw.c
@@ -71,9 +71,7 @@ sw * sw_init_cast
*s = (sw) tag->data.s8;
return s;
case TAG_STR:
- if (! sw_init_str(s, &tag->data.str))
- return NULL;
- return s;
+ return sw_init_str(s, &tag->data.str);
case TAG_U8:
*s = (sw) tag->data.u8;
return s;
diff --git a/libkc3/u.c.in b/libkc3/u.c.in
index 4aae172..88c320a 100644
--- a/libkc3/u.c.in
+++ b/libkc3/u.c.in
@@ -54,20 +54,22 @@ u_bits$ * u_bits$_init_cast
case TAG_RATIO:
*u = ratio_to_u_bits$(&tag->data.ratio);
return u;
- case TAG_SW:
- *u = (u_bits$) tag->data.sw;
+ case TAG_S8:
+ *u = (u_bits$) tag->data.s8;
return u;
- case TAG_S64:
- *u = (u_bits$) tag->data.s64;
+ case TAG_S16:
+ *u = (u_bits$) tag->data.s16;
return u;
case TAG_S32:
*u = (u_bits$) tag->data.s32;
return u;
- case TAG_S16:
- *u = (u_bits$) tag->data.s16;
+ case TAG_S64:
+ *u = (u_bits$) tag->data.s64;
return u;
- case TAG_S8:
- *u = (u_bits$) tag->data.s8;
+ case TAG_STR:
+ return u_bits$_init_str(u, &tag->data.str);
+ case TAG_SW:
+ *u = (u_bits$) tag->data.sw;
return u;
case TAG_U8:
*u = (u_bits$) tag->data.u8;
diff --git a/libkc3/u16.c b/libkc3/u16.c
index b093681..43ea2af 100644
--- a/libkc3/u16.c
+++ b/libkc3/u16.c
@@ -54,20 +54,22 @@ u16 * u16_init_cast
case TAG_RATIO:
*u = ratio_to_u16(&tag->data.ratio);
return u;
- case TAG_SW:
- *u = (u16) tag->data.sw;
+ case TAG_S8:
+ *u = (u16) tag->data.s8;
return u;
- case TAG_S64:
- *u = (u16) tag->data.s64;
+ case TAG_S16:
+ *u = (u16) tag->data.s16;
return u;
case TAG_S32:
*u = (u16) tag->data.s32;
return u;
- case TAG_S16:
- *u = (u16) tag->data.s16;
+ case TAG_S64:
+ *u = (u16) tag->data.s64;
return u;
- case TAG_S8:
- *u = (u16) tag->data.s8;
+ case TAG_STR:
+ return u16_init_str(u, &tag->data.str);
+ case TAG_SW:
+ *u = (u16) tag->data.sw;
return u;
case TAG_U8:
*u = (u16) tag->data.u8;
diff --git a/libkc3/u32.c b/libkc3/u32.c
index d10e282..5a4dc6d 100644
--- a/libkc3/u32.c
+++ b/libkc3/u32.c
@@ -54,20 +54,22 @@ u32 * u32_init_cast
case TAG_RATIO:
*u = ratio_to_u32(&tag->data.ratio);
return u;
- case TAG_SW:
- *u = (u32) tag->data.sw;
+ case TAG_S8:
+ *u = (u32) tag->data.s8;
return u;
- case TAG_S64:
- *u = (u32) tag->data.s64;
+ case TAG_S16:
+ *u = (u32) tag->data.s16;
return u;
case TAG_S32:
*u = (u32) tag->data.s32;
return u;
- case TAG_S16:
- *u = (u32) tag->data.s16;
+ case TAG_S64:
+ *u = (u32) tag->data.s64;
return u;
- case TAG_S8:
- *u = (u32) tag->data.s8;
+ case TAG_STR:
+ return u32_init_str(u, &tag->data.str);
+ case TAG_SW:
+ *u = (u32) tag->data.sw;
return u;
case TAG_U8:
*u = (u32) tag->data.u8;
diff --git a/libkc3/u64.c b/libkc3/u64.c
index c909495..c7d6c26 100644
--- a/libkc3/u64.c
+++ b/libkc3/u64.c
@@ -54,20 +54,22 @@ u64 * u64_init_cast
case TAG_RATIO:
*u = ratio_to_u64(&tag->data.ratio);
return u;
- case TAG_SW:
- *u = (u64) tag->data.sw;
+ case TAG_S8:
+ *u = (u64) tag->data.s8;
return u;
- case TAG_S64:
- *u = (u64) tag->data.s64;
+ case TAG_S16:
+ *u = (u64) tag->data.s16;
return u;
case TAG_S32:
*u = (u64) tag->data.s32;
return u;
- case TAG_S16:
- *u = (u64) tag->data.s16;
+ case TAG_S64:
+ *u = (u64) tag->data.s64;
return u;
- case TAG_S8:
- *u = (u64) tag->data.s8;
+ case TAG_STR:
+ return u64_init_str(u, &tag->data.str);
+ case TAG_SW:
+ *u = (u64) tag->data.sw;
return u;
case TAG_U8:
*u = (u64) tag->data.u8;
diff --git a/libkc3/u8.c b/libkc3/u8.c
index 9f5a414..4de42ac 100644
--- a/libkc3/u8.c
+++ b/libkc3/u8.c
@@ -54,20 +54,22 @@ u8 * u8_init_cast
case TAG_RATIO:
*u = ratio_to_u8(&tag->data.ratio);
return u;
- case TAG_SW:
- *u = (u8) tag->data.sw;
+ case TAG_S8:
+ *u = (u8) tag->data.s8;
return u;
- case TAG_S64:
- *u = (u8) tag->data.s64;
+ case TAG_S16:
+ *u = (u8) tag->data.s16;
return u;
case TAG_S32:
*u = (u8) tag->data.s32;
return u;
- case TAG_S16:
- *u = (u8) tag->data.s16;
+ case TAG_S64:
+ *u = (u8) tag->data.s64;
return u;
- case TAG_S8:
- *u = (u8) tag->data.s8;
+ case TAG_STR:
+ return u8_init_str(u, &tag->data.str);
+ case TAG_SW:
+ *u = (u8) tag->data.sw;
return u;
case TAG_U8:
*u = (u8) tag->data.u8;
diff --git a/libkc3/uw.c b/libkc3/uw.c
index 3db6bab..8230885 100644
--- a/libkc3/uw.c
+++ b/libkc3/uw.c
@@ -54,20 +54,22 @@ uw * uw_init_cast
case TAG_RATIO:
*u = ratio_to_uw(&tag->data.ratio);
return u;
- case TAG_SW:
- *u = (uw) tag->data.sw;
+ case TAG_S8:
+ *u = (uw) tag->data.s8;
return u;
- case TAG_S64:
- *u = (uw) tag->data.s64;
+ case TAG_S16:
+ *u = (uw) tag->data.s16;
return u;
case TAG_S32:
*u = (uw) tag->data.s32;
return u;
- case TAG_S16:
- *u = (uw) tag->data.s16;
+ case TAG_S64:
+ *u = (uw) tag->data.s64;
return u;
- case TAG_S8:
- *u = (uw) tag->data.s8;
+ case TAG_STR:
+ return uw_init_str(u, &tag->data.str);
+ case TAG_SW:
+ *u = (uw) tag->data.sw;
return u;
case TAG_U8:
*u = (uw) tag->data.u8;