Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you represent fraction in F# without the loss of precision?

What is best way to represent fractions in F#? Haskell and Racket have convinient way to represent ratios. Is there a data type in F# to represent ratios?

like image 829
unj2 Avatar asked Mar 17 '11 02:03

unj2


People also ask

How do you represent a fraction?

A fraction represents the number of parts that we have of a whole that is divided into equal parts. Fractions are represented by two numbers that are separated by a fraction line.

How do you represent 1/3 on a number line?

To represent 1/3 on a number line, we divide the gap between O and A into 3 equal parts. Let T and Q be the points of division. Then, T represents 1/3 and Q represents 2/3, because 2/3 means 2 parts out of 3 equal parts as shown below. By using the same procedure, point O represents 0/3 and point A represents 3/3.


1 Answers

You can use the F# Powerpack which has a BigRational (arbitrary precision rational numbers) type:

let r = (1N/2N) * (1N/3N) // 1/6
like image 129
Gabe Avatar answered Sep 30 '22 13:09

Gabe