|
Revision 2225, 1.2 kB
(checked in by chf, 5 months ago)
|
bignums: result of pair programming with GLS
|
| Line | |
|---|
| 1 |
(******************************************************************************* |
|---|
| 2 |
Copyright 2008 Sun Microsystems, Inc., |
|---|
| 3 |
4150 Network Circle, Santa Clara, California 95054, U.S.A. |
|---|
| 4 |
All rights reserved. |
|---|
| 5 |
|
|---|
| 6 |
U.S. Government Rights - Commercial software. |
|---|
| 7 |
Government users are subject to the Sun Microsystems, Inc. standard |
|---|
| 8 |
license agreement and applicable provisions of the FAR and its supplements. |
|---|
| 9 |
|
|---|
| 10 |
Use is subject to license terms. |
|---|
| 11 |
|
|---|
| 12 |
This distribution may include materials developed by third parties. |
|---|
| 13 |
|
|---|
| 14 |
Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered |
|---|
| 15 |
trademarks of Sun Microsystems, Inc. in the U.S. and other countries. |
|---|
| 16 |
******************************************************************************) |
|---|
| 17 |
|
|---|
| 18 |
component BigNum |
|---|
| 19 |
export Executable |
|---|
| 20 |
|
|---|
| 21 |
factorial(n:ZZ32):ZZ |
|---|
| 22 |
requires {n >= 0} |
|---|
| 23 |
= if n = 0 then big(1) |
|---|
| 24 |
else (factorial (n-1)) n |
|---|
| 25 |
end |
|---|
| 26 |
|
|---|
| 27 |
run(args:String...):()=do |
|---|
| 28 |
x:ZZ = 1934791870947204798109283471902037419 |
|---|
| 29 |
y:ZZ = big(1) |
|---|
| 30 |
assert (x+y ,1934791870947204798109283471902037420, "BigNum + doesn't work") |
|---|
| 31 |
assert (factorial(5), 120, "factorial(5)=120") |
|---|
| 32 |
assert (factorial(30) DIV factorial(29), 30, "factorial test failed") |
|---|
| 33 |
end |
|---|
| 34 |
|
|---|
| 35 |
end |
|---|
| 36 |
|
|---|