llvm / llvm/llvm-project

[Flang] Wrong result for quad complex exponentiation to complex unit power

Open
#192,418 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

flang
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Flang produces incorrect results when exponentiating quad precision complex values to the complex unit power (1,0). The operation should return the input value unchanged, but instead returns incorrect results.

Expected Behavior: For any complex value z, the expression z ** (1,0) should return z unchanged. This is a mathematical identity: raising any number to the power of 1 equals the number itself.

Actual Behavior: When exponentiating certain quad precision complex values (such as (3,0)) to the complex unit power (1,0), the result differs from the input value by a small error.

Reproducer :

program test
  integer, parameter :: rk = selected_real_kind(30)

  real(rk), parameter :: x_ct = 3.0
  real(rk) :: x_rt
  if (real(x_ct**(1,0),rk) /= 3.0_rk) then
     print 2, real(x_ct**(1,0),rk)
  else
     print'("ok")'
  end if
  call s()
  if (real(x_rt**(1,0),rk) /= 3.0_rk) then
     print 2, real(x_rt**(1,0),rk)
  else
     print'("ok")'
  end if

2 Format ("Should be exactly 3.00...0", 1PE45.35)
contains
  subroutine s()
    character(3) :: src
    src="3.0"
    read (src,*) x_rt
  end subroutine s

end program test

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied Fortran reproducer with Flang and compare both exponentiation results against the expected exact value. Trace the implementation of quad-precision complex exponentiation for the complex unit power, then add or update coverage so the reproducer returns its input unchanged.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.