More on e
There’s more about e on Wolfram’s Mathworld site. That site is incredible. It always comes up in google when I’m looking for math stuff. Sometimes the explanations are a little over my head, but it’s mostly good.
There’s more about e on Wolfram’s Mathworld site. That site is incredible. It always comes up in google when I’m looking for math stuff. Sometimes the explanations are a little over my head, but it’s mostly good.
Still trying to learn OCaml. This tutorial is pretty good so far.
The right way to call a function with two arguments is actually function_name arg1 arg2. function arg1, arg2 and function(arg1, arg2) apparently mean different things. The first is a function with two arguments and I think both the second and the third are functions with one argument that is a list of two elements. This is still new to me, so hopefully I can make corrections and learn by posting here.
For my Programming Languages class, we had to calculate e using the Maclaurin series 1/0! + 1/1! + 1/2! .. 1/n! in Fortran IV, Fortran II, and C and print some info about it out to the screen. I wrote it in OCaml during one of his lectures. OCaml has two numeric types int and float (makes sense so far) but has different operators for integer and float operation (umm) and I couldn’t figure out a clean way to mix ints and floats. Look at the nasty casting I do here:
let rec factorial n =
if (n < 2) then
1
else
n * factorial(n-1)
;;
let rec calculate_e precision =
if (precision<2.0) then
2.0
else
1.0/.float_of_int(factorial(int_of_float(precision))) +.
calculate_e(precision-.1.0);;
let how_precise = read_float();;
print_string (string_of_float(calculate_e(how_precise)));;
print_newline();;
There’s gotta be a better way. By the way, I gotta admit writing it in Fortran was kinda fun too.
0.090 || Powered by WordPress