ref: acb375efc5fc5c7e52f12e48dcf7e0410e68f5e7
parent: 2f2e574cc824695de2d5e2b233063afd6e7814bb
author: Ori Bernstein <[email protected]>
date: Tue Sep 16 22:07:54 EDT 2014
Add support for absolute cutoffs.
--- a/libstd/extremum.myr
+++ b/libstd/extremum.myr
@@ -2,6 +2,7 @@
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 abs = {a : @a::numeric
+ if a < (0 castto(@a::numeric))
+ -> -a
+ else
+ -> a
+ ;;
+}
--- a/libstd/floatfmt.myr
+++ b/libstd/floatfmt.myr
@@ -8,6 +8,7 @@
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 @@
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 @@
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 format = {buf, d, k
- const dig = "0123456789"
+ const dig = "0123456789abcdefghijklmnopqrstuvwxyz"
var n, i
n = 0
--- a/parse/type.c
+++ b/parse/type.c
@@ -530,13 +530,13 @@
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);