On Sun, Oct 19, 2014 at 6:45 AM, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:> On Sun, Oct 19, 2014 at 06:31:24AM +0700, C Bergström wrote: > > I apologize that I haven't been able to follow this thread entirely, but > if > > someone gives me a Fortran testcase I can check what Fortran+llvm would > do > > currently and maybe give more feedback. > > Short version: if you multiple or divide a complex number by a real > number, is it valid to just do the trivial component wise computation? > What about multiplying with / dividing by a pure imaginary number? >I'll try to get a solid answer, but for clarity.. Fortran has types REAL and CMPLX. I'm not sure if you mean INT or REAL when you say "real" number.. https://gcc.gnu.org/onlinedocs/gfortran/CMPLX.html https://gcc.gnu.org/onlinedocs/gfortran/REAL.html -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141019/5245a4f3/attachment.html>
On Sun, Oct 19, 2014 at 06:58:53AM +0700, C Bergström wrote:> On Sun, Oct 19, 2014 at 6:45 AM, Joerg Sonnenberger <joerg at britannica.bec.de > > wrote: > > > On Sun, Oct 19, 2014 at 06:31:24AM +0700, C Bergström wrote: > > > I apologize that I haven't been able to follow this thread entirely, but > > if > > > someone gives me a Fortran testcase I can check what Fortran+llvm would > > do > > > currently and maybe give more feedback. > > > > Short version: if you multiple or divide a complex number by a real > > number, is it valid to just do the trivial component wise computation? > > What about multiplying with / dividing by a pure imaginary number? > > > > I'll try to get a solid answer, but for clarity.. Fortran has types REAL > and CMPLX. I'm not sure if you mean INT or REAL when you say "real" number..I am using "real" in the mathematical sense, so cast/promotion from either INT or REAL would fit. Joerg
On Oct 18, 2014, at 5:25 PM, Joerg Sonnenberger <joerg at britannica.bec.de> wrote:> On Sun, Oct 19, 2014 at 06:58:53AM +0700, C Bergström wrote: >> On Sun, Oct 19, 2014 at 6:45 AM, Joerg Sonnenberger <joerg at britannica.bec.de >>> wrote: >> >>> On Sun, Oct 19, 2014 at 06:31:24AM +0700, C Bergström wrote: >>>> I apologize that I haven't been able to follow this thread entirely, but >>> if >>>> someone gives me a Fortran testcase I can check what Fortran+llvm would >>> do >>>> currently and maybe give more feedback. >>> >>> Short version: if you multiple or divide a complex number by a real >>> number, is it valid to just do the trivial component wise computation? >>> What about multiplying with / dividing by a pure imaginary number? >>> >> >> I'll try to get a solid answer, but for clarity.. Fortran has types REAL >> and CMPLX. I'm not sure if you mean INT or REAL when you say "real" number.. > > I am using "real" in the mathematical sense, so cast/promotion from > either INT or REAL would fit.Mathematically, a*(b+ic) = ab +iac where a, b, and c are arbitrary real numbers. Division by nonzero a is identical to multiplication by 1/a. I have no idea what language specs say, however. In general, multiplying complex numbers in rectangular form is pretty straight-forward: (a+ib)(c+id) = ac - bd + i(ad+bc). Division is a little more of a hassle: (a+ib)/(c+id) = (a+ib)(c-id)/(c^2 + d^2) = (ac + bd)/(c^2 + d^2) + i(bc - ad)/(c^2 + d^2). (Polar form is more convenient for multiplication and division: a*exp(is) * b*exp(it) = ab*exp(i(s+t)) and division by nonzero a*exp(is) is the same as multiplication by 1/a exp(-is). Addition and subtraction become annoying though.) -- Stephen Checkoway