Jump to content

  •  

Photo

Working with Floats

Code Snippet

  • Please log in to reply
No replies to this topic

#1 Wilson18

Wilson18

    Administrator

  • root
  • 112 posts
  • LocationUniversity of Birmingham

Posted 02 November 2014 - 06:35 PM

When working with any kind of float in OCaml (any number which has a decimal point), you will have to treat differently. If you are wanting to add two floats together, you will no longer be able to use the standard + simple. you will have to do so like I have in the code below:


(* Errors for not using the correct code *)

1.3 * 3.0;;
4.5 + 4.5;;
123.4 / 3.1;;

The Errors:

Attached File  Screen Shot 2014-11-02 at 18.33.03.png   83.86KB   0 downloads

The correct way of doing it

(* The correct way of doing these *)

1.3 *. 3.0;;
4.5 +. 4.5;;
123.4 /. 3.1;;

The Answers

Attached File  Screen Shot 2014-11-02 at 18.34.49.png   33.74KB   0 downloads

 

 

 


List what you read?

Check me out on: YouTube, Twitter, Facebook, Google+






Also tagged with one or more of these keywords: Code Snippet