test/hotspot/jtreg/compiler/c2/PolynomialRoot.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 40631 hotspot/test/compiler/c2/PolynomialRoot.java@ed82623d7831
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     1
/*
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     2
 * (C) Vladislav Malyshkin 2010
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     3
 * This file is under GPL version 3.
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     4
 *
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     5
 */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     6
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     7
/** Polynomial root.
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     8
 *  @version $Id: PolynomialRoot.java,v 1.105 2012/08/18 00:00:05 mal Exp $
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     9
 *  @author Vladislav Malyshkin mal@gromco.com
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    10
 */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    11
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    12
/**
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    13
 * @test
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    14
 * @bug 8005956
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    15
 * @summary C2: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG defined in this block
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    16
 * @library /test/lib
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    17
 * @modules java.base/jdk.internal.misc
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    18
 *          java.management
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    19
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    20
 * @run main/timeout=300 compiler.c2.PolynomialRoot
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    21
 */
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    22
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    23
package compiler.c2;
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    24
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    25
import jdk.test.lib.Utils;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 36851
diff changeset
    26
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 18698
diff changeset
    27
import java.util.Arrays;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 18698
diff changeset
    28
import java.util.Random;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 18698
diff changeset
    29
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    30
public class PolynomialRoot  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    31
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    32
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    33
public static int findPolynomialRoots(final int n,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    34
              final double [] p,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    35
              final double [] re_root,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    36
              final double [] im_root)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    37
{
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    38
    if(n==4)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    39
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    40
  return root4(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    41
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    42
    else if(n==3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    43
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    44
  return root3(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    45
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    46
    else if(n==2)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    47
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    48
  return root2(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    49
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    50
    else if(n==1)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    51
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    52
  return root1(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    53
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    54
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    55
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    56
  throw new RuntimeException("n="+n+" is not supported yet");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    57
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    58
}
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    59
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    60
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    61
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    62
static final double SQRT3=Math.sqrt(3.0),SQRT2=Math.sqrt(2.0);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    63
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    64
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    65
private static final boolean PRINT_DEBUG=false;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    66
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    67
public static int root4(final double [] p,final double [] re_root,final double [] im_root)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    68
{
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 18698
diff changeset
    69
  if (PRINT_DEBUG) { System.err.println("=====================root4:p=" + Arrays.toString(p)); }
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    70
  final double vs=p[4];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    71
  if(PRINT_DEBUG) System.err.println("p[4]="+p[4]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    72
  if(!(Math.abs(vs)>EPS))
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    73
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    74
      re_root[0]=re_root[1]=re_root[2]=re_root[3]=
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    75
    im_root[0]=im_root[1]=im_root[2]=im_root[3]=Double.NaN;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    76
      return -1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    77
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    78
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    79
/* zsolve_quartic.c - finds the complex roots of
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    80
 *  x^4 + a x^3 + b x^2 + c x + d = 0
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    81
 */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    82
  final double a=p[3]/vs,b=p[2]/vs,c=p[1]/vs,d=p[0]/vs;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    83
  if(PRINT_DEBUG) System.err.println("input a="+a+" b="+b+" c="+c+" d="+d);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    84
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    85
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    86
  final double r4 = 1.0 / 4.0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    87
  final double q2 = 1.0 / 2.0, q4 = 1.0 / 4.0, q8 = 1.0 / 8.0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    88
  final double q1 = 3.0 / 8.0, q3 = 3.0 / 16.0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    89
  final int mt;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    90
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    91
  /* Deal easily with the cases where the quartic is degenerate. The
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    92
   * ordering of solutions is done explicitly. */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    93
  if (0 == b && 0 == c)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    94
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    95
      if (0 == d)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    96
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    97
    re_root[0]=-a;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    98
    im_root[0]=im_root[1]=im_root[2]=im_root[3]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    99
    re_root[1]=re_root[2]=re_root[3]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   100
    return 4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   101
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   102
      else if (0 == a)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   103
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   104
    if (d > 0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   105
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   106
        final double sq4 = Math.sqrt(Math.sqrt(d));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   107
        re_root[0]=sq4*SQRT2/2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   108
        im_root[0]=re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   109
        re_root[1]=-re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   110
        im_root[1]=re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   111
        re_root[2]=-re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   112
        im_root[2]=-re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   113
        re_root[3]=re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   114
        im_root[3]=-re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   115
        if(PRINT_DEBUG) System.err.println("Path a=0 d>0");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   116
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   117
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   118
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   119
        final double sq4 = Math.sqrt(Math.sqrt(-d));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   120
        re_root[0]=sq4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   121
        im_root[0]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   122
        re_root[1]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   123
        im_root[1]=sq4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   124
        re_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   125
        im_root[2]=-sq4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   126
        re_root[3]=-sq4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   127
        im_root[3]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   128
        if(PRINT_DEBUG) System.err.println("Path a=0 d<0");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   129
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   130
    return 4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   131
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   132
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   133
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   134
  if (0.0 == c && 0.0 == d)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   135
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   136
      root2(new double []{p[2],p[3],p[4]},re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   137
      re_root[2]=im_root[2]=re_root[3]=im_root[3]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   138
      return 4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   139
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   140
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   141
  if(PRINT_DEBUG) System.err.println("G Path c="+c+" d="+d);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   142
  final double [] u=new double[3];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   143
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   144
  if(PRINT_DEBUG) System.err.println("Generic Path");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   145
  /* For non-degenerate solutions, proceed by constructing and
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   146
   * solving the resolvent cubic */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   147
  final double aa = a * a;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   148
  final double pp = b - q1 * aa;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   149
  final double qq = c - q2 * a * (b - q4 * aa);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   150
  final double rr = d - q4 * a * (c - q4 * a * (b - q3 * aa));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   151
  final double rc = q2 * pp , rc3 = rc / 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   152
  final double sc = q4 * (q4 * pp * pp - rr);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   153
  final double tc = -(q8 * qq * q8 * qq);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   154
  if(PRINT_DEBUG) System.err.println("aa="+aa+" pp="+pp+" qq="+qq+" rr="+rr+" rc="+rc+" sc="+sc+" tc="+tc);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   155
  final boolean flag_realroots;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   156
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   157
  /* This code solves the resolvent cubic in a convenient fashion
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   158
   * for this implementation of the quartic. If there are three real
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   159
   * roots, then they are placed directly into u[].  If two are
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   160
   * complex, then the real root is put into u[0] and the real
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   161
   * and imaginary part of the complex roots are placed into
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   162
   * u[1] and u[2], respectively. */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   163
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   164
      final double qcub = (rc * rc - 3 * sc);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   165
      final double rcub = (rc*(2 * rc * rc - 9 * sc) + 27 * tc);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   166
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   167
      final double Q = qcub / 9;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   168
      final double R = rcub / 54;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   169
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   170
      final double Q3 = Q * Q * Q;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   171
      final double R2 = R * R;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   172
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   173
      final double CR2 = 729 * rcub * rcub;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   174
      final double CQ3 = 2916 * qcub * qcub * qcub;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   175
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   176
      if(PRINT_DEBUG) System.err.println("CR2="+CR2+" CQ3="+CQ3+" R="+R+" Q="+Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   177
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   178
      if (0 == R && 0 == Q)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   179
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   180
    flag_realroots=true;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   181
    u[0] = -rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   182
    u[1] = -rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   183
    u[2] = -rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   184
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   185
      else if (CR2 == CQ3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   186
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   187
    flag_realroots=true;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   188
    final double sqrtQ = Math.sqrt (Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   189
    if (R > 0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   190
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   191
        u[0] = -2 * sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   192
        u[1] = sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   193
        u[2] = sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   194
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   195
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   196
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   197
        u[0] = -sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   198
        u[1] = -sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   199
        u[2] = 2 * sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   200
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   201
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   202
      else if (R2 < Q3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   203
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   204
    flag_realroots=true;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   205
    final double ratio = (R >= 0?1:-1) * Math.sqrt (R2 / Q3);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   206
    final double theta = Math.acos (ratio);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   207
    final double norm = -2 * Math.sqrt (Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   208
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   209
    u[0] = norm * Math.cos (theta / 3) - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   210
    u[1] = norm * Math.cos ((theta + 2.0 * Math.PI) / 3) - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   211
    u[2] = norm * Math.cos ((theta - 2.0 * Math.PI) / 3) - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   212
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   213
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   214
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   215
    flag_realroots=false;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   216
    final double A = -(R >= 0?1:-1)*Math.pow(Math.abs(R)+Math.sqrt(R2-Q3),1.0/3.0);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   217
    final double B = Q / A;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   218
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   219
    u[0] = A + B - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   220
    u[1] = -0.5 * (A + B) - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   221
    u[2] = -(SQRT3*0.5) * Math.abs (A - B);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   222
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   223
      if(PRINT_DEBUG) System.err.println("u[0]="+u[0]+" u[1]="+u[1]+" u[2]="+u[2]+" qq="+qq+" disc="+((CR2 - CQ3) / 2125764.0));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   224
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   225
  /* End of solution to resolvent cubic */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   226
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   227
  /* Combine the square roots of the roots of the cubic
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   228
   * resolvent appropriately. Also, calculate 'mt' which
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   229
   * designates the nature of the roots:
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   230
   * mt=1 : 4 real roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   231
   * mt=2 : 0 real roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   232
   * mt=3 : 2 real roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   233
   */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   234
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   235
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   236
  final double w1_re,w1_im,w2_re,w2_im,w3_re,w3_im,mod_w1w2,mod_w1w2_squared;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   237
  if (flag_realroots)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   238
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   239
      mod_w1w2=-1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   240
      mt = 2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   241
      int jmin=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   242
      double vmin=Math.abs(u[jmin]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   243
      for(int j=1;j<3;j++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   244
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   245
    final double vx=Math.abs(u[j]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   246
    if(vx<vmin)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   247
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   248
        vmin=vx;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   249
        jmin=j;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   250
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   251
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   252
      final double u1=u[(jmin+1)%3],u2=u[(jmin+2)%3];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   253
      mod_w1w2_squared=Math.abs(u1*u2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   254
      if(u1>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   255
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   256
    w1_re=Math.sqrt(u1);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   257
    w1_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   258
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   259
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   260
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   261
    w1_re=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   262
    w1_im=Math.sqrt(-u1);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   263
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   264
      if(u2>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   265
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   266
    w2_re=Math.sqrt(u2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   267
    w2_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   268
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   269
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   270
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   271
    w2_re=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   272
    w2_im=Math.sqrt(-u2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   273
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   274
      if(PRINT_DEBUG) System.err.println("u1="+u1+" u2="+u2+" jmin="+jmin);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   275
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   276
  else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   277
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   278
      mt = 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   279
      final double w_mod2_sq=u[1]*u[1]+u[2]*u[2],w_mod2=Math.sqrt(w_mod2_sq),w_mod=Math.sqrt(w_mod2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   280
      if(w_mod2_sq<=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   281
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   282
    w1_re=w1_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   283
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   284
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   285
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   286
    // calculate square root of a complex number (u[1],u[2])
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   287
    // the result is in the (w1_re,w1_im)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   288
    final double absu1=Math.abs(u[1]),absu2=Math.abs(u[2]),w;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   289
    if(absu1>=absu2)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   290
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   291
        final double t=absu2/absu1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   292
        w=Math.sqrt(absu1*0.5 * (1.0 + Math.sqrt(1.0 + t * t)));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   293
        if(PRINT_DEBUG) System.err.println(" Path1 ");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   294
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   295
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   296
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   297
        final double t=absu1/absu2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   298
        w=Math.sqrt(absu2*0.5 * (t + Math.sqrt(1.0 + t * t)));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   299
        if(PRINT_DEBUG) System.err.println(" Path1a ");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   300
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   301
    if(u[1]>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   302
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   303
        w1_re=w;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   304
        w1_im=u[2]/(2*w);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   305
        if(PRINT_DEBUG) System.err.println(" Path2 ");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   306
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   307
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   308
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   309
        final double vi = (u[2] >= 0) ? w : -w;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   310
        w1_re=u[2]/(2*vi);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   311
        w1_im=vi;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   312
        if(PRINT_DEBUG) System.err.println(" Path2a ");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   313
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   314
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   315
      final double absu0=Math.abs(u[0]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   316
      if(w_mod2>=absu0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   317
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   318
    mod_w1w2=w_mod2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   319
    mod_w1w2_squared=w_mod2_sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   320
    w2_re=w1_re;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   321
    w2_im=-w1_im;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   322
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   323
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   324
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   325
    mod_w1w2=-1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   326
    mod_w1w2_squared=w_mod2*absu0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   327
    if(u[0]>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   328
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   329
        w2_re=Math.sqrt(absu0);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   330
        w2_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   331
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   332
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   333
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   334
        w2_re=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   335
        w2_im=Math.sqrt(absu0);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   336
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   337
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   338
      if(PRINT_DEBUG) System.err.println("u[0]="+u[0]+"u[1]="+u[1]+" u[2]="+u[2]+" absu0="+absu0+" w_mod="+w_mod+" w_mod2="+w_mod2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   339
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   340
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   341
  /* Solve the quadratic in order to obtain the roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   342
   * to the quartic */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   343
  if(mod_w1w2>0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   344
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   345
      // a shorcut to reduce rounding error
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   346
      w3_re=qq/(-8)/mod_w1w2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   347
      w3_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   348
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   349
  else if(mod_w1w2_squared>0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   350
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   351
      // regular path
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   352
      final double mqq8n=qq/(-8)/mod_w1w2_squared;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   353
      w3_re=mqq8n*(w1_re*w2_re-w1_im*w2_im);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   354
      w3_im=-mqq8n*(w1_re*w2_im+w2_re*w1_im);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   355
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   356
  else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   357
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   358
      // typically occur when qq==0
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   359
      w3_re=w3_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   360
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   361
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   362
  final double h = r4 * a;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   363
  if(PRINT_DEBUG) System.err.println("w1_re="+w1_re+" w1_im="+w1_im+" w2_re="+w2_re+" w2_im="+w2_im+" w3_re="+w3_re+" w3_im="+w3_im+" h="+h);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   364
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   365
  re_root[0]=w1_re+w2_re+w3_re-h;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   366
  im_root[0]=w1_im+w2_im+w3_im;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   367
  re_root[1]=-(w1_re+w2_re)+w3_re-h;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   368
  im_root[1]=-(w1_im+w2_im)+w3_im;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   369
  re_root[2]=w2_re-w1_re-w3_re-h;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   370
  im_root[2]=w2_im-w1_im-w3_im;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   371
  re_root[3]=w1_re-w2_re-w3_re-h;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   372
  im_root[3]=w1_im-w2_im-w3_im;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   373
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   374
  return 4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   375
}
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   376
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   377
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   378
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 18698
diff changeset
   379
    static void setRandomP(final double [] p, final int n, Random r)
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   380
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   381
  if(r.nextDouble()<0.1)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   382
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   383
      // integer coefficiens
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   384
      for(int j=0;j<p.length;j++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   385
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   386
    if(j<=n)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   387
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   388
        p[j]=(r.nextInt(2)<=0?-1:1)*r.nextInt(10);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   389
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   390
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   391
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   392
        p[j]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   393
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   394
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   395
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   396
  else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   397
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   398
      // real coefficiens
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   399
      for(int j=0;j<p.length;j++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   400
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   401
    if(j<=n)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   402
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   403
        p[j]=-1+2*r.nextDouble();
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   404
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   405
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   406
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   407
        p[j]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   408
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   409
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   410
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   411
  if(Math.abs(p[n])<1e-2)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   412
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   413
      p[n]=(r.nextInt(2)<=0?-1:1)*(0.1+r.nextDouble());
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   414
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   415
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   416
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   417
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   418
    static void checkValues(final double [] p,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   419
          final int n,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   420
          final double rex,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   421
          final double imx,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   422
          final double eps,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   423
          final String txt)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   424
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   425
  double res=0,ims=0,sabs=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   426
  final double xabs=Math.abs(rex)+Math.abs(imx);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   427
  for(int k=n;k>=0;k--)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   428
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   429
      final double res1=(res*rex-ims*imx)+p[k];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   430
      final double ims1=(ims*rex+res*imx);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   431
      res=res1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   432
      ims=ims1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   433
      sabs+=xabs*sabs+p[k];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   434
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   435
  sabs=Math.abs(sabs);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   436
  if(false && sabs>1/eps?
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   437
     (!(Math.abs(res/sabs)<=eps)||!(Math.abs(ims/sabs)<=eps))
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   438
     :
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   439
     (!(Math.abs(res)<=eps)||!(Math.abs(ims)<=eps)))
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   440
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   441
      throw new RuntimeException(
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   442
    getPolinomTXT(p)+"\n"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   443
    "\t x.r="+rex+" x.i="+imx+"\n"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   444
    "res/sabs="+(res/sabs)+" ims/sabs="+(ims/sabs)+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   445
    " sabs="+sabs+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   446
    "\nres="+res+" ims="+ims+" n="+n+" eps="+eps+" "+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   447
    " sabs>1/eps="+(sabs>1/eps)+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   448
    " f1="+(!(Math.abs(res/sabs)<=eps)||!(Math.abs(ims/sabs)<=eps))+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   449
    " f2="+(!(Math.abs(res)<=eps)||!(Math.abs(ims)<=eps))+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   450
    " "+txt);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   451
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   452
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   453
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   454
    static String getPolinomTXT(final double [] p)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   455
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   456
  final StringBuilder buf=new StringBuilder();
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   457
  buf.append("order="+(p.length-1)+"\t");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   458
  for(int k=0;k<p.length;k++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   459
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   460
      buf.append("p["+k+"]="+p[k]+";");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   461
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   462
  return buf.toString();
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   463
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   464
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   465
    static String getRootsTXT(int nr,final double [] re,final double [] im)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   466
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   467
  final StringBuilder buf=new StringBuilder();
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   468
  for(int k=0;k<nr;k++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   469
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   470
      buf.append("x."+k+"("+re[k]+","+im[k]+")\n");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   471
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   472
  return buf.toString();
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   473
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   474
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   475
    static void testRoots(final int n,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   476
        final int n_tests,
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 18698
diff changeset
   477
        final Random rn,
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   478
        final double eps)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   479
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   480
  final double [] p=new double [n+1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   481
  final double [] rex=new double [n],imx=new double [n];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   482
  for(int i=0;i<n_tests;i++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   483
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   484
    for(int dg=n;dg-->-1;)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   485
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   486
      for(int dr=3;dr-->0;)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   487
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   488
        setRandomP(p,n,rn);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   489
        for(int j=0;j<=dg;j++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   490
        {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   491
      p[j]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   492
        }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   493
        if(dr==0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   494
        {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   495
      p[0]=-1+2.0*rn.nextDouble();
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   496
        }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   497
        else if(dr==1)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   498
        {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   499
      p[0]=p[1]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   500
        }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   501
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   502
        findPolynomialRoots(n,p,rex,imx);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   503
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   504
        for(int j=0;j<n;j++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   505
        {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   506
      //System.err.println("j="+j);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   507
      checkValues(p,n,rex[j],imx[j],eps," t="+i);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   508
        }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   509
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   510
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   511
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   512
  System.err.println("testRoots(): n_tests="+n_tests+" OK, dim="+n);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   513
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   514
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   515
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   516
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   517
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   518
    static final double EPS=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   519
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   520
    public static int root1(final double [] p,final double [] re_root,final double [] im_root)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   521
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   522
  if(!(Math.abs(p[1])>EPS))
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   523
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   524
      re_root[0]=im_root[0]=Double.NaN;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   525
      return -1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   526
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   527
  re_root[0]=-p[0]/p[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   528
  im_root[0]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   529
  return 1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   530
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   531
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   532
    public static int root2(final double [] p,final double [] re_root,final double [] im_root)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   533
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   534
  if(!(Math.abs(p[2])>EPS))
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   535
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   536
      re_root[0]=re_root[1]=im_root[0]=im_root[1]=Double.NaN;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   537
      return -1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   538
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   539
  final double b2=0.5*(p[1]/p[2]),c=p[0]/p[2],d=b2*b2-c;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   540
  if(d>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   541
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   542
      final double sq=Math.sqrt(d);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   543
      if(b2<0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   544
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   545
    re_root[1]=-b2+sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   546
    re_root[0]=c/re_root[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   547
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   548
      else if(b2>0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   549
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   550
    re_root[0]=-b2-sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   551
    re_root[1]=c/re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   552
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   553
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   554
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   555
    re_root[0]=-b2-sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   556
    re_root[1]=-b2+sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   557
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   558
      im_root[0]=im_root[1]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   559
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   560
  else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   561
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   562
      final double sq=Math.sqrt(-d);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   563
      re_root[0]=re_root[1]=-b2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   564
      im_root[0]=sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   565
      im_root[1]=-sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   566
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   567
  return 2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   568
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   569
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   570
    public static int root3(final double [] p,final double [] re_root,final double [] im_root)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   571
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   572
  final double vs=p[3];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   573
  if(!(Math.abs(vs)>EPS))
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   574
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   575
      re_root[0]=re_root[1]=re_root[2]=
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   576
    im_root[0]=im_root[1]=im_root[2]=Double.NaN;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   577
      return -1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   578
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   579
  final double a=p[2]/vs,b=p[1]/vs,c=p[0]/vs;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   580
  /* zsolve_cubic.c - finds the complex roots of x^3 + a x^2 + b x + c = 0
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   581
   */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   582
  final double q = (a * a - 3 * b);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   583
  final double r = (a*(2 * a * a - 9 * b) + 27 * c);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   584
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   585
  final double Q = q / 9;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   586
  final double R = r / 54;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   587
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   588
  final double Q3 = Q * Q * Q;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   589
  final double R2 = R * R;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   590
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   591
  final double CR2 = 729 * r * r;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   592
  final double CQ3 = 2916 * q * q * q;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   593
  final double a3=a/3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   594
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   595
  if (R == 0 && Q == 0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   596
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   597
      re_root[0]=re_root[1]=re_root[2]=-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   598
      im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   599
      return 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   600
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   601
  else if (CR2 == CQ3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   602
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   603
      /* this test is actually R2 == Q3, written in a form suitable
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   604
         for exact computation with integers */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   605
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   606
      /* Due to finite precision some double roots may be missed, and
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   607
         will be considered to be a pair of complex roots z = x +/-
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   608
         epsilon i close to the real axis. */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   609
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   610
      final double sqrtQ = Math.sqrt (Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   611
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   612
      if (R > 0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   613
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   614
    re_root[0] = -2 * sqrtQ - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   615
    re_root[1]=re_root[2]=sqrtQ - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   616
    im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   617
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   618
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   619
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   620
    re_root[0]=re_root[1] = -sqrtQ - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   621
    re_root[2]=2 * sqrtQ - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   622
    im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   623
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   624
      return 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   625
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   626
  else if (R2 < Q3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   627
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   628
      final double sgnR = (R >= 0 ? 1 : -1);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   629
      final double ratio = sgnR * Math.sqrt (R2 / Q3);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   630
      final double theta = Math.acos (ratio);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   631
      final double norm = -2 * Math.sqrt (Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   632
      final double r0 = norm * Math.cos (theta/3) - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   633
      final double r1 = norm * Math.cos ((theta + 2.0 * Math.PI) / 3) - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   634
      final double r2 = norm * Math.cos ((theta - 2.0 * Math.PI) / 3) - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   635
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   636
      re_root[0]=r0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   637
      re_root[1]=r1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   638
      re_root[2]=r2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   639
      im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   640
      return 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   641
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   642
  else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   643
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   644
      final double sgnR = (R >= 0 ? 1 : -1);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   645
      final double A = -sgnR * Math.pow (Math.abs (R) + Math.sqrt (R2 - Q3), 1.0 / 3.0);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   646
      final double B = Q / A;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   647
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   648
      re_root[0]=A + B - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   649
      im_root[0]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   650
      re_root[1]=-0.5 * (A + B) - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   651
      im_root[1]=-(SQRT3*0.5) * Math.abs(A - B);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   652
      re_root[2]=re_root[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   653
      im_root[2]=-im_root[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   654
      return 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   655
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   656
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   657
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   658
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   659
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   660
    static void root3a(final double [] p,final double [] re_root,final double [] im_root)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   661
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   662
  if(Math.abs(p[3])>EPS)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   663
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   664
      final double v=p[3],
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   665
    a=p[2]/v,b=p[1]/v,c=p[0]/v,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   666
    a3=a/3,a3a=a3*a,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   667
    pd3=(b-a3a)/3,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   668
    qd2=a3*(a3a/3-0.5*b)+0.5*c,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   669
    Q=pd3*pd3*pd3+qd2*qd2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   670
      if(Q<0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   671
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   672
    // three real roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   673
    final double SQ=Math.sqrt(-Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   674
    final double th=Math.atan2(SQ,-qd2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   675
    im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   676
    final double f=2*Math.sqrt(-pd3);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   677
    re_root[0]=f*Math.cos(th/3)-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   678
    re_root[1]=f*Math.cos((th+2*Math.PI)/3)-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   679
    re_root[2]=f*Math.cos((th+4*Math.PI)/3)-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   680
    //System.err.println("3r");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   681
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   682
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   683
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   684
    // one real & two complex roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   685
    final double SQ=Math.sqrt(Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   686
    final double r1=-qd2+SQ,r2=-qd2-SQ;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   687
    final double v1=Math.signum(r1)*Math.pow(Math.abs(r1),1.0/3),
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   688
        v2=Math.signum(r2)*Math.pow(Math.abs(r2),1.0/3),
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   689
        sv=v1+v2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   690
    // real root
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   691
    re_root[0]=sv-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   692
    im_root[0]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   693
    // complex roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   694
    re_root[1]=re_root[2]=-0.5*sv-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   695
    im_root[1]=(v1-v2)*(SQRT3*0.5);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   696
    im_root[2]=-im_root[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   697
    //System.err.println("1r2c");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   698
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   699
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   700
  else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   701
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   702
      re_root[0]=re_root[1]=re_root[2]=im_root[0]=im_root[1]=im_root[2]=Double.NaN;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   703
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   704
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   705
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   706
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   707
    static void printSpecialValues()
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   708
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   709
  for(int st=0;st<6;st++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   710
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   711
      //final double [] p=new double []{8,1,3,3.6,1};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   712
      final double [] re_root=new double [4],im_root=new double [4];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   713
      final double [] p;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   714
      final int n;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   715
      if(st<=3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   716
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   717
    if(st<=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   718
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   719
        p=new double []{2,-4,6,-4,1};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   720
        //p=new double []{-6,6,-6,8,-2};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   721
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   722
    else if(st==1)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   723
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   724
        p=new double []{0,-4,8,3,-9};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   725
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   726
    else if(st==2)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   727
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   728
        p=new double []{-1,0,2,0,-1};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   729
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   730
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   731
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   732
        p=new double []{-5,2,8,-2,-3};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   733
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   734
    root4(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   735
    n=4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   736
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   737
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   738
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   739
    p=new double []{0,2,0,1};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   740
    if(st==4)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   741
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   742
        p[1]=-p[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   743
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   744
    root3(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   745
    n=3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   746
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   747
      System.err.println("======== n="+n);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   748
      for(int i=0;i<=n;i++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   749
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   750
    if(i<n)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   751
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   752
        System.err.println(String.valueOf(i)+"\t"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   753
               p[i]+"\t"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   754
               re_root[i]+"\t"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   755
               im_root[i]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   756
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   757
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   758
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   759
        System.err.println(String.valueOf(i)+"\t"+p[i]+"\t");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   760
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   761
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   762
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   763
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   764
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   765
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   766
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   767
    public static void main(final String [] args)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   768
    {
18698
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   769
      if (System.getProperty("os.arch").equals("x86") ||
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   770
         System.getProperty("os.arch").equals("amd64") ||
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   771
         System.getProperty("os.arch").equals("x86_64")){
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   772
        final long t0=System.currentTimeMillis();
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   773
        final double eps=1e-6;
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   774
        //checkRoots();
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 18698
diff changeset
   775
        final Random r = Utils.getRandomInstance();
18698
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   776
        printSpecialValues();
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   777
18698
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   778
        final int n_tests=100000;
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   779
        //testRoots(2,n_tests,r,eps);
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   780
        //testRoots(3,n_tests,r,eps);
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   781
        testRoots(4,n_tests,r,eps);
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   782
        final long t1=System.currentTimeMillis();
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   783
        System.err.println("PolynomialRoot.main: "+n_tests+" tests OK done in "+(t1-t0)+" milliseconds. ver=$Id: PolynomialRoot.java,v 1.105 2012/08/18 00:00:05 mal Exp $");
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   784
        System.out.println("PASSED");
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   785
     } else {
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   786
       System.out.println("PASS test for non-x86");
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   787
     }
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   788
   }
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   789
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   790
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   791
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   792
}