1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fraction: simplify variable names

This commit is contained in:
Hungry Blue Dev 2020-05-13 22:09:19 +05:30 committed by GitHub
parent 2e0b9de31c
commit 3270545953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -164,42 +164,42 @@ pub fn (f1 Fraction) divide(f2 Fraction) Fraction {
}
// Fraction negate method
pub fn (f1 Fraction) negate() Fraction {
pub fn (f Fraction) negate() Fraction {
return Fraction{
n: -f1.n
d: f1.d
is_reduced: f1.is_reduced
n: -f.n
d: f.d
is_reduced: f.is_reduced
}
}
// Fraction reciprocal method
pub fn (f1 Fraction) reciprocal() Fraction {
if f1.n == 0 {
pub fn (f Fraction) reciprocal() Fraction {
if f.n == 0 {
panic('Denominator cannot be zero')
}
return Fraction{
n: f1.d
d: f1.n
is_reduced: f1.is_reduced
n: f.d
d: f.n
is_reduced: f.is_reduced
}
}
// Fraction method which reduces the fraction
pub fn (f1 Fraction) reduce() Fraction {
if f1.is_reduced {
return f1
pub fn (f Fraction) reduce() Fraction {
if f.is_reduced {
return f
}
cf := math.gcd(f1.n, f1.d)
cf := math.gcd(f.n, f.d)
return Fraction{
n: f1.n / cf
d: f1.d / cf
n: f.n / cf
d: f.d / cf
is_reduced: true
}
}
// f64 converts the Fraction to 64-bit floating point
pub fn (f1 Fraction) f64() f64 {
return f64(f1.n) / f64(f1.d)
pub fn (f Fraction) f64() f64 {
return f64(f.n) / f64(f.d)
}
//