.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Math::Cephes::Fraction 3pm" .TH Math::Cephes::Fraction 3pm "2021-06-22" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" .Vb 1 \& Math::Cephes::Fraction \- Perl interface to the cephes math fraction routines .Ve .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& use Math::Cephes::Fraction qw(fract); \& my $f1 = fract(2,3); # $f1 = 2/3 \& my $f2 = fract(3,4); # $f2 = 3/4 \& my $f3 = $f1\->radd($f2); # $f3 = $f1 + $f2 .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module is a layer on top of the basic routines in the cephes math library to handle fractions. A fraction object is created via any of the following syntaxes: .PP .Vb 3 \& my $f = Math::Cephes::Fraction\->new(3, 2); # $f = 3/2 \& my $g = new Math::Cephes::Fraction(5, 3); # $g = 5/3 \& my $h = fract(7, 5); # $h = 7/5 .Ve .PP the last one being available by importing \fI:fract\fR. If no arguments are specified, as in .PP .Vb 1 \& my $h = fract(); .Ve .PP then the defaults \f(CW$z\fR = 0/1 are assumed. The numerator and denominator of a fraction are represented respectively by .PP .Vb 1 \& $f\->{n}; $f\->{d} .Ve .PP or, as methods, .PP .Vb 1 \& $f\->n; $f\->d; .Ve .PP and can be set according to .PP .Vb 1 \& $f\->{n} = 4; $f\->{d} = 9; .Ve .PP or, again, as methods, .PP .Vb 1 \& $f\->n(4) ; $f\->(d) = 9; .Ve .PP The fraction can be printed out as .PP .Vb 1 \& print $f\->as_string; .Ve .PP or as a mixed fraction as .PP .Vb 1 \& print $f\->as_mixed_string; .Ve .PP These routines reduce the fraction to its basic form before printing. This uses the \fIeuclid\fR routine which finds the greatest common divisor of two numbers, as follows: .PP .Vb 1 \& ($gcd, $m_reduced, $n_reduced) = euclid($m, $n); .Ve .PP which returns the greatest common divisor of \f(CW$m\fR and \f(CW$n\fR, as well as the result of reducing \f(CW$m\fR and \f(CW$n\fR by \f(CW$gcd\fR .PP A summary of the basic routines is as follows. .PP .Vb 9 \& $x = fract(3, 4); # x = 3 / 4 \& $y = fract(2, 3); # y = 2 / 3 \& $z = $x\->radd( $y ); # z = x + y \& $z = $x\->rsub( $y ); # z = x \- y \& $z = $x\->rmul( $y ); # z = x * y \& $z = $x\->rdiv( $y ); # z = x / y \& print $z\->{n}, \*(Aq \*(Aq, $z\->{d}; # prints numerator and denominator of $z \& print $z\->as_string; # prints the fraction $z \& print $z\->as_mixed_string; # converts $z to a mixed fraction, then prints it \& \& $m = 60; \& $n = 144; \& ($gcd, $m_reduced, $n_reduced) = euclid($m, $n); .Ve .SH "BUGS" .IX Header "BUGS" Please report any to Randy Kobes .SH "SEE ALSO" .IX Header "SEE ALSO" For the basic interface to the cephes fraction routines, see Math::Cephes. See also Math::Fraction for a more extensive interface to fraction routines. .SH "COPYRIGHT" .IX Header "COPYRIGHT" The C code for the Cephes Math Library is Copyright 1984, 1987, 1989, 2002 by Stephen L. Moshier, and is available at http://www.netlib.org/cephes/. Direct inquiries to 30 Frost Street, Cambridge, \s-1MA 02140.\s0 .PP The perl interface is copyright 2000, 2002 by Randy Kobes. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.