[Nickle] nickle: Branch 'master' - 4 commits
Keith Packard
keithp at keithp.com
Mon Jul 5 22:22:19 PDT 2010
math.5c | 3 ---
pretty.c | 2 +-
prime_sieve.5c | 2 +-
test/Makefile.am | 3 ++-
test/factorial.5c | 33 +++++++++++++++++++++++++++++++++
5 files changed, 37 insertions(+), 6 deletions(-)
New commits:
commit 601affcbaf587816a6be4b6815efd2cc99cff66e
Author: Keith Packard <keithp at keithp.com>
Date: Tue Jul 6 01:20:50 2010 -0400
Fix prime sieve function to include 'max' when 'max' is prime
The sieve code would drop the max value from the returned list when it
was prime.
Signed-off-by: Keith Packard <keithp at keithp.com>
diff --git a/prime_sieve.5c b/prime_sieve.5c
index 751455b..25aca84 100644
--- a/prime_sieve.5c
+++ b/prime_sieve.5c
@@ -26,7 +26,7 @@ public namespace PrimeSieve {
*/
public int[] primes (int max)
{
- int n = num_to_pos(max+1);
+ int n = num_to_pos(max) + 1;
bool[n] composite = { false ... };
int n_prime = 0;
commit d341e0220d181db50f7a6647433053293b3f45ec
Author: Keith Packard <keithp at keithp.com>
Date: Tue Jul 6 01:20:11 2010 -0400
Fix factorial pretty-printing
The expr tree built for factorial is different now, so the pretty
print code needs to adapt.
Signed-off-by: Keith Packard <keithp at keithp.com>
diff --git a/pretty.c b/pretty.c
index a7632a0..cc3ae09 100644
--- a/pretty.c
+++ b/pretty.c
@@ -509,7 +509,7 @@ PrettyExpr (Value f, Expr *e, int parentPrec, int level, Bool nest)
PrettyExpr (f, e->tree.right, selfPrec, level, nest);
break;
case FACT:
- PrettyExpr (f, e->tree.left, selfPrec, level, nest);
+ PrettyExpr (f, e->tree.right, selfPrec, level, nest);
FilePuts (f, "!");
break;
case LNOT:
commit 6d4a60c69eac89ff72004a00a8e9a70876db2325
Author: Keith Packard <keithp at keithp.com>
Date: Tue Jul 6 01:19:15 2010 -0400
Add factorial test
This tests factorial accuracy up to 1000, which should
catch most errors
Signed-off-by: Keith Packard <keithp at keithp.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 96e9f89..7ab6cb7 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -8,7 +8,8 @@ check_SCRIPTS=gcdtest.5c \
hashtest.5c \
signal.5c \
round.5c \
- math.5c
+ math.5c \
+ factorial.5c
noinst_PROGRAMS=math-tables
diff --git a/test/factorial.5c b/test/factorial.5c
new file mode 100644
index 0000000..b2589cc
--- /dev/null
+++ b/test/factorial.5c
@@ -0,0 +1,33 @@
+/*
+ * Nickle test suite
+ *
+ * factorial tests
+ */
+
+int errors = 0;
+
+int fact(int n) {
+ int r = 1;
+ while (n > 1) {
+ r *= n;
+ n--;
+ }
+ return r;
+}
+
+void check_factorial(int max) {
+ for (int n = 0; n < max; n++) {
+ int is = n!;
+ int should = fact(n);
+
+ if (is != should) {
+ printf ("check failed %d! (was %d should be %d)\n",
+ n, is, should);
+ ++errors;
+ }
+ }
+}
+
+check_factorial(1000);
+
+exit (errors);
commit 75187037e714eaadc671daba19a934608fd1069b
Author: Keith Packard <keithp at keithp.com>
Date: Tue Jul 6 01:18:08 2010 -0400
Remove accidentally included cos debug printf
This was accidentally added in the previous patch
Signed-off-by: Keith Packard <keithp at keithp.com>
diff --git a/math.5c b/math.5c
index b25028e..a6cd170 100644
--- a/math.5c
+++ b/math.5c
@@ -648,10 +648,8 @@ extend namespace Math {
a4 = a**4;
iter = prec + 8;
v = 0;
- int niter = 0;
while (iter-- > 0)
{
- niter++;
term = ai/i! - aj/j!;
v += term;
if (exponent (v) > exponent (term) + iprec)
@@ -661,7 +659,6 @@ extend namespace Math {
i += 4;
j += 4;
}
- printf ("cos: %d iters\n", niter);
return imprecise (v + term);
}
More information about the Nickle
mailing list