List:General Discussion« Previous MessageNext Message »
From:Michael T. Babcock Date:September 23 2002 1:13pm
Subject:Re: Fractions
View as plain text  
MySQL wrote:

>   You might also consider using two integer type fields - one for the
>   numerator and another for the denominator. This way storage and recovery are
>   easy and the mathematics are wide open.
>   _M
>
>I suspect that a float add is faster than 3 integer multiplies and
>sum.
>  
>
It depends on why you're storing this information in the first place. 
 If what you want is the precision of fractions (which you lose with 
floating point), then store the numerator and denominator.  If you want 
quick and dirty calculations at certain points in your code, store both ...

Example (where $x, $y are variables):
INSERT INTO FracTable (numerator, denominator, appxval) values ($x, $y, 
$x/$y);

-- 
Michael T. Babcock
C.T.O., FibreSpeed Ltd.
http://www.fibrespeed.net/~mbabcock


Thread
FractionsWilliam Martell19 Sep
  • Re: FractionsPaul DuBois19 Sep
    • Re: FractionsMySQL20 Sep
      • RE: FractionsMadscientist20 Sep
        • Re: FractionsMySQL21 Sep
        • Re: FractionsMichael T. Babcock23 Sep
  • Re: FractionsThomas Spahni19 Sep
Re: FractionsMichael T. Babcock19 Sep
Re: FractionsJan Steinman22 Sep