From 9bf1d123b8b66431dcb5d281f4850bd21a620037 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 7 Apr 2024 03:40:19 +0630 Subject: Changed limit for examples/factorial.asm Did some analysis and found that 21! takes above 64 bit integers to store hence set the limit to 20 instead. --- examples/factorial.asm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/factorial.asm b/examples/factorial.asm index 42c0785..54fc956 100644 --- a/examples/factorial.asm +++ b/examples/factorial.asm @@ -1,9 +1,12 @@ ;;; factorial.asm: A program that generates the factorials of each -;;; number from 1 to 22 (22!~=UINT64_MAX). Using the registers to -;;; store `n` and `n!`. +;;; number from 1 to 20. Using the registers to store `n` and `n!`. ;; Constants - %const(limit) 22 %end + ;; Choice of 20 was not arbitrary; log(20!) ~= 61 while log(21!) ~= + ;; 65 which means that past 20! results are truncated and therefore + ;; the program produces inaccurate factorials. + + %const(limit) 20 %end ;; Setup entrypoint global main -- cgit v1.2.3-13-gbd6f