caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Johann Spies <jspies@maties.sun.ac.za>
To: ocaml mailing list <caml-list@inria.fr>
Subject: [Caml-list] out-of-bound array or string access
Date: 10 Oct 2001 12:12:03 +0200	[thread overview]
Message-ID: <874rp7reh8.fsf@bywoner.sun.ac.za> (raw)

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


             reply	other threads:[~2001-10-10 10:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-10 10:12 Johann Spies [this message]
2001-10-10 10:31 ` Alain Frisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874rp7reh8.fsf@bywoner.sun.ac.za \
    --to=jspies@maties.sun.ac.za \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).