summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libstd/extremum.myr8
-rw-r--r--libstd/floatfmt.myr64
-rw-r--r--parse/type.c6
3 files changed, 63 insertions, 15 deletions
diff --git a/libstd/extremum.myr b/libstd/extremum.myr
index bf496ad..9675915 100644
--- a/libstd/extremum.myr
+++ b/libstd/extremum.myr
@@ -2,6 +2,7 @@ pkg std =
generic min : (a : @a::numeric, b : @a::numeric -> @a::numeric)
generic max : (a : @a::numeric, b : @a::numeric -> @a::numeric)
generic clamp : (a : @a::numeric, min : @a::numeric, max : @a::numeric -> @a::numeric)
+ generic abs : (a : @a::numeric -> @a::numeric)
;;
generic min = {a, b
@@ -30,3 +31,10 @@ generic clamp = {a, min, max
;;
}
+generic abs = {a : @a::numeric
+ if a < (0 castto(@a::numeric))
+ -> -a
+ else
+ -> a
+ ;;
+}
diff --git a/libstd/floatfmt.myr b/libstd/floatfmt.myr
index 370385d..480f3b8 100644
--- a/libstd/floatfmt.myr
+++ b/libstd/floatfmt.myr
@@ -8,6 +8,7 @@ use "slpush.use"
use "die.use"
pkg std =
+
const float64bfmt : (buf : byte[:], val : float64, mode : int, precision : int -> size)
const float32bfmt : (buf : byte[:], val : float32, mode : int, precision : int -> size)
;;
@@ -38,12 +39,13 @@ f: mantissa
floating value: x = f^(e - p)
*/
const dragon4 = {buf, isneg, f, e, p, mode, cutoff
- var r, s, t, u, v
+ var r, s, t, u, v, y
var udig
var mm, mp /* margins above and below */
var roundup
var low, high
- var k : int, n : size
+ var k, n
+ var a, i
/* if we have zero for the mantissa, we can return early */
n = 0
@@ -94,24 +96,62 @@ const dragon4 = {buf, isneg, f, e, p, mode, cutoff
bigfree(t)
;;
- t = bigdup(r)
- bigshli(t, 1)
- bigadd(t, mp)
while true
+ t = bigdup(r)
+ bigshli(t, 1)
+ bigadd(t, mp)
+ while true
+ u = bigdup(s)
+ bigshli(u, 1)
+ match bigcmp(t, u)
+ | `Before:
+ bigfree(u)
+ break
+ | _:
+ k++
+ bigmuli(s, 10)
+ bigfree(u)
+ ;;
+ ;;
+ match mode
+ | 0:
+ cutoff = k - buf.len - 1
+ | 1:
+ a = cutoff - k
+ y = bigdup(s)
+ if a < 0
+ for i = 0; i < a; i++
+ bigmuli(y, 10)
+ ;;
+ else
+ for i = 0; i < -a; i++
+ bigaddi(y, 9)
+ bigdivi(y, 10)
+ ;;
+ ;;
+ match bigcmp(y, mm)
+ | `Before: /* nothing */
+ | _:
+ bigfree(mm)
+ mm = y
+ ;;
+ match bigcmp(y, mp)
+ | `Before: /* nothing */
+ | _:
+ bigfree(mp)
+ mm = y
+ ;;
+ | 2:
+ ;;
u = bigdup(s)
bigshli(u, 1)
match bigcmp(t, u)
| `Before:
+ bigfree(t)
bigfree(u)
break
- | _:
- k++
- bigmuli(s, 10)
- bigfree(u)
;;
;;
- cutoff = k - buf.len - 1
- bigfree(t)
if k <= 0
n += encode(buf[n:], '0')
@@ -179,7 +219,7 @@ const lowdig = {u
}
const format = {buf, d, k
- const dig = "0123456789"
+ const dig = "0123456789abcdefghijklmnopqrstuvwxyz"
var n, i
n = 0
diff --git a/parse/type.c b/parse/type.c
index dc61202..8955ba7 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -530,13 +530,13 @@ static int tybfmt(char *buf, size_t len, Type *t)
p += snprintf(p, end - p, ")");
break;
case Tytuple:
- p += snprintf(p, end - p, "[");
+ p += snprintf(p, end - p, "(");
for (i = 0; i < t->nsub; i++) {
p += snprintf(p, end - p, "%s", sep);
p += tybfmt(p, end - p, t->sub[i]);
- sep = ", ";
+ sep = ",";
}
- p += snprintf(p, end - p, "]");
+ p += snprintf(p, end - p, ")");
break;
case Tyvar:
p += snprintf(p, end - p, "$%d", t->tid);