[Nickle] nickle: Branch 'master'
Bart Massey
bart at keithp.com
Mon Sep 8 00:38:13 PDT 2008
builtin-toplevel.c | 8 ++++++++
builtin.c | 8 ++++++++
float.c | 13 ++++++++++++-
3 files changed, 28 insertions(+), 1 deletion(-)
New commits:
commit 0eb425902db7e6291afb881086aef5a4a4e5019f
Author: Bart Massey <bart at cs.pdx.edu>
Date: Mon Sep 8 00:37:58 2008 -0700
added variable to control default floating point precision
diff --git a/builtin-toplevel.c b/builtin-toplevel.c
index 7a2236d..88d2cea 100644
--- a/builtin-toplevel.c
+++ b/builtin-toplevel.c
@@ -368,9 +368,17 @@ do_imprecise (int n, Value *p)
}
else
{
+ Value float_prec;
if (ValueIsFloat(v))
RETURN(v);
prec = DEFAULT_FLOAT_PREC;
+ float_prec = lookupVar(0, "float_precision");
+ if (float_prec)
+ {
+ int default_prec = ValueInt(float_prec);
+ if (default_prec > 1)
+ prec = default_prec;
+ }
}
RETURN (NewValueFloat (v, prec));
diff --git a/builtin.c b/builtin.c
index 6f47c23..74d232b 100644
--- a/builtin.c
+++ b/builtin.c
@@ -51,6 +51,11 @@ static const struct filebuiltin fvars[] = {
{ 0, 0 },
};
+static const struct ibuiltin ivars[] = {
+ { DEFAULT_FLOAT_PREC, "float_precision", &GlobalNamespace },
+ { 0, 0 },
+};
+
static const struct ebuiltin excepts[] = {
{"uninitialized_value", exception_uninitialized_value, "s", "\n"
" uninitialized_value (string message)\n"
@@ -373,6 +378,9 @@ BuiltinInit (void)
BoxValueSet (sym->global.value, 0, *f->value);
}
+ /* Import int objects with predefined values */
+ BuiltinIntegers (ivars);
+
/* Import standard exceptions */
for (e = excepts; e->name; e++)
BuiltinAddException (0, e->exception, e->name, e->args, e->doc);
diff --git a/float.c b/float.c
index 12af2ec..7dd3eea 100644
--- a/float.c
+++ b/float.c
@@ -579,10 +579,21 @@ FloatPromote (Value av, Value bv)
if (!ValueIsFloat(av))
{
+ prec = DEFAULT_FLOAT_PREC;
if (bv && ValueIsFloat(bv))
+ {
prec = bv->floats.prec;
+ }
else
- prec = DEFAULT_FLOAT_PREC;
+ {
+ Value float_prec = lookupVar(0, "float_precision");
+ if (float_prec)
+ {
+ int default_prec = ValueInt(float_prec);
+ if (default_prec > 1)
+ prec = default_prec;
+ }
+ }
av = NewValueFloat (av, prec);
}
RETURN (av);
More information about the Nickle
mailing list