## Re: "ocaml_beginners"::[] Is this Power Function Tail-Recursive?

Expand Messages
• ... A number that s too big to be represented by ocaml floats (see the OCaml manual, in Pervasives Floating-point arithmetic : this is the IEEE 754
Message 1 of 9 , Apr 30, 2007
--- In ocaml_beginners@yahoogroups.com, "LORENZO" <arniwarp@...> wrote:
> What's infinity...??

A number that's too big to be represented by
ocaml floats (see the OCaml manual, in
Pervasives > Floating-point arithmetic : this is
the "IEEE 754 standard").

> Any good suggestions for my foolish trial?

Foolish indeed : The number
N=987654321^987654321 has
8883560462 digits, and the maximum string
length (Sys.max_string_length) is
16777211 (on my toplevel). So the number
is more than 800 times too long to be written out,
let alone be computed.

Otherwise, you can use the Num module (or
the Big_int module which is more specifically made
for integers):

# let self_power x=
let b_x=Big_int.big_int_of_string(x) in
val self_power : string -> string = <fun>
# let trial=self_power "987654321";;
Out of memory during evaluation. // see ? I told ya !

HTH,

Ewan
• ... infinity like nan are special floating point values. In your case, infinity is given as because the result exceededs the range of FP numbers. Other
Message 2 of 9 , May 1, 2007
On Tue, 01 May 2007, "LORENZO" <arniwarp@...> wrote:
>
> What's infinity...??
>
> # 987654321. ** 987654321.
> - : float = infinity

"infinity" like "nan" are special floating point values. In your
case, infinity is given as because the result exceededs the range of
FP numbers. Other cases : 1. /. 0. (also try 1. /. (-0.)).

My 0.02€,
ChriS
• ... Have a look at min_float, max_float, infinity, neg_infinity and nan. Consider how machines represent numbers and why they cannot do computations on huge
Message 3 of 9 , May 1, 2007
On Tuesday 01 May 2007 06:22, LORENZO wrote:
> My attempt is just to get number result of
> such a big number power itself like N ** N.
> However, when I tried the following evaluation
> at OCaml toplevel, it gave me a real smart answer...
> What's infinity...??

Have a look at min_float, max_float, infinity, neg_infinity and nan. Consider
how machines represent numbers and why they cannot do computations on huge
numbers without resorting to approximate methods.

--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e
Your message has been successfully submitted and would be delivered to recipients shortly.