Math::Fraction v.4a

This is a small demonstration of what the fraction module can do.

It is run for the most part with these two functions.

sub pevel {print ">$_[0]\n"; $ans = eval $_[0]; print " $ans\n"; }
sub evelp {print ">$_[0]\n"; eval $_[0]; } 

You can see it for yourself my typing demo in the fraction test script.

>frac(1, 3)
 1/3
>frac(4, 3, MIXED)
 1 1/3
>frac(1, 1, 3)
 4/3
>frac(1, 1, 3, MIXED)
 1 1/3
>frac(10)
 10/1
>frac(10, MIXED)
 10
>frac(.66667)
 2/3
>frac(1.33333, MIXED)
 1/3
>frac("5/6")
 5/6
>frac("1 2/3")
 5/3
>frac(10, 20, NO_REDUCE)
 10/20

>$f1=frac(2,3); $f2=frac(4,5);
>$f1 + $f2
 22/15
>$f1 * $f2
 8/15
>$f1 + 1.6667
 4/3
>$f2->modify_tag(MIXED)
>$f2 + 10
 10 4/5
>frac($ans, NORMAL) # trick to create a new fraction with different tags
 54/5
>$f1 + $f2          # Add two unlikes it goes to default mode
 22/15
>$f1**1.2
 229739670999407/373719281884655
>$f1->num**1.2
 0.614738607654485
>frac(1,2)+frac(2,5)
 9/10

>$f1=frac(5,3,NORMAL); $f2=frac(7,5);
>"$f1  $f2"
 5/3  7/5
>Math::Fraction->modify_tag(MIXED)
>"$f1  $f2"
 5/3  1 2/5
>$f1 = frac("3267893629762/32678632179820")
 3267893629762/32678632179820
>$f2 = frac("5326875886785/76893467996910")
 5326875886785/76893467996910
>$f1->is_tag(BIG).",".$f2->is_tag(BIG) # Notice how neither of them is BIG 
 0,0
>$f1+$f2
 21267734600460495169085706/125638667885089122116217810
>$ans->is_tag(BIG)                     # But this answer is.
 1
>$f1*$f2
 1740766377695750621849517/251277335770178244232435620
>$ans->is_tag(BIG)                     # And so is this one.
 1

>$f1 = frac("3267893629762/32678632179820", BIG)
 3267893629762/32678632179820
>$f1->is_tag(BIG)   # Notice how the big tag had no effect.
 0
>$f1->modify_tag(NO_AUTO, BIG)
>$f1->is_tag(BIG)   # But now it does.  You have to turn off AUTO.
 1
>$f1->num
 .10000093063197482237806917498797382196606
>Math::Fraction->modify_digits(15)
>$f1->num
 .1000009306319748
>$f1 = frac("0.123123123456456456456456456456123456789123456789123457")
 13680347037037036999999999999963000037/111111111000000000000000000000000000000
>Math::Fraction->modify_digits(75)
>$f1->num
 .1231231234564564564564564564561234567891234567891234567891234567891234567891

>$f1 = frac(7,5);
>$f2 = frac("3267893629762/32678632179820", NO_AUTO, BIG)
>Math::Fraction->modify_tag(MIXED); Math::Fraction->modify_digits(65)
>"$f1 ".$f2->num
 1 2/5 .100000930631974822378069174987973821966064776948503591249477157474
>Math::Fraction->load_set(DEFAULT)
>"$f1 ".$f2->num
 7/5 .10000093063197482237806917498797382196606
>Math::Fraction->modify_digits(25)
>"$f1 ".$f2->num
 7/5 .10000093063197482237806917
>$s = Math::Fraction->temp_set
>Math::Fraction->modify_tag(MIXED); Math::Fraction->modify_digits(15)
>"$f1 ".$f2->num
 1 2/5 .1000009306319748
>Math::Fraction->temp_set($s)
>Math::Fraction->exists_set($s)
 undef [Added by Kevin for clarity]
>"$f1 ".$f2->num  # Notice how it goes back to the previous settings.
 7/5 .10000093063197482237806917

>Math::Fraction->name_set('temp1')
>Math::Fraction->modify_tag(MIXED, NO_AUTO)
>Math::Fraction->modify_digits(60)
>&s(Math::Fraction->tags, Math::Fraction->digits)
 MIXED REDUCE SMALL NO_AUTO 60
>Math::Fraction->save_set  # If no name is given it will be saved via
>                          # its given name
>Math::Fraction->load_set(DEFAULT)
>&s(Math::Fraction->tags, Math::Fraction->digits)
 NORMAL REDUCE SMALL AUTO undef
>&s(Math::Fraction->tags('temp1'), Math::Fraction->digits('temp1'))
 MIXED REDUCE SMALL NO_AUTO 60
>  # ^^ Notice how this lets you preview other sets with out loading them.
>Math::Fraction->load_set(DEFAULT)
>Math::Fraction->use_set('temp1')
>Math::Fraction->modify_tag(NO_REDUCE)
>&s(Math::Fraction->tags, Math::Fraction->digits)
 MIXED NO_REDUCE SMALL NO_AUTO 60
>&s(Math::Fraction->tags('temp1'), Math::Fraction->digits('temp1'))
 MIXED NO_REDUCE SMALL NO_AUTO 60
>  # ^^ Notice how this also modifies the temp1 tag becuase it is being used
>  #    if it was just loaded it would not do this becuase there is no link.

