Hello, when I define following function (computes a**n where a is float

and n is int)

let rec ipow2 a n =

if n = 0 then 1. else if n = 1 then a

else

if (n mod 2) = 1 then

let an = ipow2 a (n-1)/2 in

a *. an *. an

else

let an = ipow2 a n/2 in

an *. an

I get following error:

This expression has type float but is here used with type int

However, when I define the function like this

let rec ipow2 a n =

if n = 0 then 1. else if n = 1 then a

else

if (n mod 2) = 1 then

let n2 = (n-1)/2 in

let an = ipow2 a n2 in

a *. an *. an

else

let n2 = n/2 in

let an = (ipow2 a n2) in

an *. an

it is accepted. I don't understand what is wrong in the first

definition. Can somebody explain? I am using "The Objective Caml

toplevel, version 3.10.2". Thank you.

[Non-text portions of this message have been removed]