[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Johann Spies <jspies@m...> |
| Subject: | [Caml-list] out-of-bound array or string access |
When I run this small program I get the following results:
------------------------
$ ./paaiement 10000 13.5 5
Die paaiement is R230.10
--------------------------
All arguments correct. Result as expected...
--------------------------
$ ./paaiement 10000 -13.5 5
Die rentekoers (-13.500000) moet tussen 0 en 100.0 wees
-------------------------
Second argument negative - not acceptable. Output as expected.
-------------------------------
$ ./paaiement 10000 -13.5 5 6
Gebruik: paaiement <bedrag> <rentekoers p.j.> <aantal_jare>
--------------------------------
Arguments > 4 - output as expected.
-------------------------------
$ ./paaiement 10000 -13.5
Fatal error: uncaught exception Invalid_argument("out-of-bound array
or string access")
---------------------------------
Arguments < 4 - unexpected error.
Why did "if Array.length Sys.argv <> 4 then " not catch this?
The code:
-------------------------------------------
let maandelikse_koers koers = koers /. 100.0/. 12.0;;
let n jare = jare *. 12.0;;
let paaiement rentekoers jare bedrag =
(bedrag *. (maandelikse_koers rentekoers) /. (1.0 -. exp
((-.n jare) *. log (1.0 +. (maandelikse_koers rentekoers)))));;
let bedrag = float_of_string Sys.argv.(1);;
let rentekoers = float_of_string Sys.argv.(2);;
let jare = float_of_string Sys.argv.(3);;
let main() = if Array.length Sys.argv <> 4 then
begin
print_string
"Gebruik: paaiement <bedrag> <rentekoers p.j.> <aantal_jare>\n";
print_newline();
exit 2
end
else
if rentekoers >= 0. then
Printf.printf "\nDie paaiement is R%04.2f\n"
(paaiement rentekoers jare bedrag)
else
begin
Printf.printf
"Die rentekoers (%f) moet tussen 0 en 100.0 wees" rentekoers ;
print_newline();
exit 2;
end ;;
main();
print_newline();
-------------------------------------------------
I am again missing something here.
Regards
Johann
--
Johann Spies Telefoon: 021-808 4036
Informasietegnologie, Universiteit van Stellenbosch
"He that covereth his sins shall not prosper; but whoso
confesseth and forsaketh them shall have mercy."
Proverbs 28:13
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr