FoscFraction

Returns a FoscFraction.


Description

Fractions


Attributes Summary

Instance Methods: Special Methods

+
-
*
/
==
===
!=
<
>
<=
>=
abs
asCompileString
asFloat
asInteger
copy
deepCopy
div
hash
mod
neg
pow
reciprocal
sign
storeArgs
str

Instance Methods

withDenominator


Usage

  1. Example

    FoscFraction(3).cs;
    FoscFraction(3, 1)
    FoscFraction(3.14159).cs;
    FoscFraction(355, 113)
    FoscFraction(#[3,2]).cs;
    FoscFraction(3, 2)
    FoscFraction(6,2).cs;
    FoscFraction(3, 1)
    FoscNonreducedFraction(6,2).cs;
    FoscNonreducedFraction(6, 2)
    FoscFraction().cs;
    FoscFraction(0, 1)


Instance Methods: Special Methods


+

  1. Example

    a = FoscFraction(3,2) + FoscFraction(1,2);
    a.str;
    2/1
  2. Example

    a = FoscFraction(3,2) + 0.5;
    a.str;
    2/1
  3. Example

    a = 1.5 + FoscFraction(1,2);
    a.str;
    2/1


-

  1. Example

    a = FoscFraction(3,2) - FoscFraction(1,2);
    a.str;
    1/1
  2. Example

    a = FoscFraction(3,2) - 0.5;
    a.str;
    1/1
  3. Example

    a = 1.5 - FoscFraction(1,2);
    a.str;
    1/1


*

  1. Example

    a = FoscFraction(3,2) * FoscFraction(1,2);
    a.str;
    3/4
  2. Example

    a = FoscFraction(3,2) * 0.5;
    a.str;
    3/4
  3. Example

    a = 0.5 * FoscFraction(3,2);
    a.str;
    3/4


/

  1. Example

    a = FoscFraction(3,2) / FoscFraction(1,2);
    a.str;
    3/1
  2. Example

    a = FoscFraction(3,2) / 0.5;
    a.str;
    3/1
  3. Example

    a = 1.5 / FoscFraction(1,2);
    a.str;
    3/1


==

  1. Example

    a = FoscFraction(3,2);
    b = FoscFraction(6,4);
    c = FoscFraction(2,1);
    d = 2;
    
    a == a;     // true
    true
    a == b;     // true
    true
    a == c;     // false
    false
    c == d;     // true
    true
    d == c;     // true
    true


===

  1. Example

    a = FoscFraction(3,2);
    b = FoscFraction(6,4);
    c = FoscFraction(2,1);
    d = 2;
    
    a === a;     // true
    true
    a === b;     // true  !!!TODO: override for FoscNonreducedFraction
    true
    a === c;     // false
    false
    c === d;     // true
    true
    d === c;     // true
    false


!=

  1. Example

    a = FoscFraction(3,2);
    b = FoscFraction(6,4);
    c = FoscFraction(2,1);
    d = 2;
    
    a != a;     // false
    false
    a != b;     // false
    false
    a != c;     // true
    true
    c != d;     // false
    false
    d != c;     // false
    false


<

  1. Example

    a = FoscFraction(3,2);
    b = FoscFraction(6,4);
    c = FoscFraction(2,1);
    d = 2;
    
    a < a;     // false
    false
    a < b;     // false
    false
    a < c;     // true
    true
    c < d;     // false
    false
    d < c;     // false
    false


>

  1. Example

    a = FoscFraction(3,2);
    b = FoscFraction(6,4);
    c = FoscFraction(2,1);
    d = 2;
    
    a > a;     // false
    false
    a > b;     // false
    false
    a > c;     // true
    false
    c > b;     // true
    true
    b > c;     // false
    false


<=

  1. Example

    a = FoscFraction(3,2);
    b = FoscFraction(6,4);
    c = FoscFraction(2,1);
    d = 2;
    
    a <= a;     // true
    true
    a <= b;     // true
    true
    a <= c;     // true
    true
    c <= d;     // true
    true
    d <= c;     // true
    true


>=

  1. Example

    a = FoscFraction(3,2);
    b = FoscFraction(6,4);
    c = FoscFraction(2,1);
    d = 2;
    
    a >= a;     // true
    true
    a >= b;     // true
    true
    a >= c;     // false
    false
    c >= d;     // true
    true
    d >= c;     // true
    true


abs

  1. Example

    a = FoscFraction(-3,2).abs;
    a.str;
    3/2


asCompileString

  1. Example

    a = FoscFraction(1,4);
    a.cs;
    FoscFraction(1, 4)


asFloat

  1. Example

    a = FoscFraction(3,2);
    a.asFloat;
    1.5


asInteger

  1. Example

    a = FoscFraction(5,2);
    a.asInteger;
    2


copy


deepCopy


div

  1. Example

    a = FoscFraction(3,2).div(FoscFraction(1,2));
    a.str;
    3/1
    a = FoscFraction(3,2).div(0.5);
    a.str;
    3/1
    a = 1.5.div(FoscFraction(1,2));
    a.str;
    3/1


hash

  1. Example

    a = FoscFraction([1,4]);
    b = FoscFraction([1,4]);
    a.hash;
    -929596897
    a.hash == b.hash;
    true


mod

  1. Example

    a = FoscFraction(3,2) % FoscFraction(1,2);
    a.str;
    0/1
    a = FoscFraction(3,2) % 0.5;
    a.str;
    0/1
    a = 1.5 % FoscFraction(1,2);
    a.str;
    0/1


neg

  1. Example

    a = FoscFraction(3,2).neg;
    a.str;
    -3/2


pow

  1. Example

    a = FoscFraction(3,2) ** FoscFraction(2,1);
    a.str;
    9/4
    a = FoscFraction(3,2) ** 2;
    a.str;
    9/4
    a = 1.5 ** FoscFraction(2,1);
    a.str;
    9/4


reciprocal

  1. Example

    a = FoscFraction(3,2);
    a.reciprocal.str;
    2/3


sign

  1. Example

    a = FoscFraction(3,4);
    a.sign;
    1
    a = FoscFraction(-3,4);
    a.sign;
    -1


storeArgs


str

  1. Example

    a = FoscFraction(3,2);
    a.str;
    3/2


Instance Methods


withDenominator

  1. Example

    a = FoscNonreducedFraction(3,2);
    a = a.withDenominator(4);
    a.pair;
    [ 6, 4 ]