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?
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.
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.
You can use the F# Powerpack which has a BigRational
(arbitrary precision rational numbers) type:
let r = (1N/2N) * (1N/3N) // 1/6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With