[REBOL] Re: optimising recursion?
From: joel::neely::fedex::com at: 20-Mar-2002 6:24
Hi, Petr,
You must have a 2Gb or larger disk... ;-)
Try changing the inital value of TOTAL to floating point
and see if it helps.
Petr Krenzelok wrote:
> Hi,
>
> is my function conceptually wrong? It fails on very large network
> directory ....
>
> REBOL []
>
> dir-size?: func [path [file!] /local dir-list total tmp][
>
> total: 0
total: 0.0
> if not dir? path [return none] ; wrong param to func ...
>
> dir-list: read path
> if empty? dir-list [return 0] ;take care of empty dir
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Why? Won't it will simply
fall thru the following loop
without changing TOTAL from
its initial value?
> foreach item dir-list [
> either (last to-string item) = #"/" [
> tmp: dir-size? append copy path item
> total: total + tmp
> ][
> s: size? append copy path item
> if not none? s [total: total + s] ; take care
> of possibly locked file ....
> ]
> ]
> total
> ]
>
> ->> ble: dir-size? %/g/control/
> ** Math Error: Math or number overflow
> ** Where: dir-size?
> ** Near: total: total + tmp
>
I can trigger that error with a simple integer calculation which
overflows integer range, but it disappears when the calculation
is done with non-integer numbers.
>> recur-test: func [n [number!]] [
[ either zero? n [1] [2 * (recur-test n - 1) + 1]]
>> recur-test 5 == 63
>> recur-test 30 == 2147483647
>> recur-test 31
** Math Error: Math or number overflow
** Where: recur-test
** Near: 2 * (recur-test n - 1) + 1
>> recur-test 40
** Math Error: Math or number overflow
** Where: recur-test
** Near: 2 * (recur-test n - 1) + 1
>> recur-test: func [n [number!]] [
[ either zero? n [1.0] [2 * (recur-test n - 1) + 1]]
>> recur-test 30 == 2147483647
>> recur-test 31 == 4294967295
>> recur-test 40 == 2199023255551
--
; Joel Neely joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]