OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

office-formula message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [office-formula] GCD and LCM non-integer arguments


Hi Tomas,

On Friday, 2007-01-19 11:22:28 +0100, Tomas Mecir wrote:

> >> convert to INT first; non-INT GCD and LCM are interesting, but I doubt
> >> many actually WANT them.
> >Most certainly not.
> 
> Agreed here.
> 
> Is it even mathematically possible to compute this sanely ?

Not if taking the "result of GCD is largest integer" constraint into
account. However, if you reduce the problem to "find the greatest common
divisor" of fractions you get

GCD(fractions) = GCD(numerators) / LCM(denominators)

after having normalized and expanded the fractions to have a common
denominator of LCM(denominators). 
With the relationship |a*b|=GCD(a;b)*LCM(a;b) you then easily get

LCM(fractions) = |fractions_product| * LCM(denominators) / GCD(numerators)

Note that this relationship holds only for two numbers, it gets more
complicated with 3 numbers and up.

> I mean, is there some algorithm for this ? While this function is
> greatly useful when operating over integers, it doesn't make sense
> with real numbers, as ANY non-zero floating-point number divides any
> other floating-point number with a floating-point result ...

For rational numbers the GCD alone IMHO is not that interesting, but you
need the GCD to compute the LCM, which in fact solves problems like "how
many of size x do you need to fit with how many of size y without
remainder and what's the overall size".

Of course you get the same answer by properly expanding the fractions,
multiply them by the value of the common denominator, apply the usual
integer GCD and at the end divide the LCM and GCD again by the common
denominator.

  Eike

-- 
Automatic string conversions considered dangerous. They are the GOTO statements
of spreadsheets.  --Robert Weir on the OpenDocument formula subcommittee's list.


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]