hotspot/test/compiler/8005956/PolynomialRoot.java
author ccheung
Fri, 04 Oct 2013 21:00:43 -0700
changeset 20384 49bfb2ec8f8f
parent 18698 862c19338ded
child 27453 9aeb9b97bef6
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     1
//package com.polytechnik.utils;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     2
/*
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     3
 * (C) Vladislav Malyshkin 2010
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     4
 * This file is under GPL version 3.
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
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     8
/** Polynomial root.
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
     9
 *  @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
    10
 *  @author Vladislav Malyshkin mal@gromco.com
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
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    13
/**
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    14
* @test
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    15
* @bug 8005956
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    16
* @summary C2: assert(!def_outside->member(r)) failed: Use of external LRG overlaps the same LRG defined in this block
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    17
*
18698
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
    18
* @run main/timeout=300 PolynomialRoot
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    19
*/
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    20
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    21
public class PolynomialRoot  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    22
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    23
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    24
public static int findPolynomialRoots(final int n,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    25
              final double [] p,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    26
              final double [] re_root,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    27
              final double [] im_root)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    28
{
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    29
    if(n==4)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    30
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    31
  return root4(p,re_root,im_root);
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
    else if(n==3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    34
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    35
  return root3(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    36
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    37
    else if(n==2)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    38
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    39
  return root2(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    40
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    41
    else if(n==1)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    42
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    43
  return root1(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    44
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    45
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    46
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    47
  throw new RuntimeException("n="+n+" is not supported yet");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    48
    }
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
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
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    53
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
    54
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
private static final boolean PRINT_DEBUG=false;
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
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
    59
{
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    60
  if(PRINT_DEBUG) System.err.println("=====================root4:p="+java.util.Arrays.toString(p));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    61
  final double vs=p[4];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    62
  if(PRINT_DEBUG) System.err.println("p[4]="+p[4]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    63
  if(!(Math.abs(vs)>EPS))
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
      re_root[0]=re_root[1]=re_root[2]=re_root[3]=
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    66
    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
    67
      return -1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    68
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    69
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    70
/* zsolve_quartic.c - finds the complex roots of
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    71
 *  x^4 + a x^3 + b x^2 + c x + d = 0
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    72
 */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    73
  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
    74
  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
    75
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    76
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    77
  final double r4 = 1.0 / 4.0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    78
  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
    79
  final double q1 = 3.0 / 8.0, q3 = 3.0 / 16.0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    80
  final int mt;
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
  /* Deal easily with the cases where the quartic is degenerate. The
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    83
   * ordering of solutions is done explicitly. */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    84
  if (0 == b && 0 == c)
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
      if (0 == d)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    87
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    88
    re_root[0]=-a;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    89
    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
    90
    re_root[1]=re_root[2]=re_root[3]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    91
    return 4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    92
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    93
      else if (0 == a)
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 (d > 0)
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
        final double sq4 = Math.sqrt(Math.sqrt(d));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    98
        re_root[0]=sq4*SQRT2/2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
    99
        im_root[0]=re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   100
        re_root[1]=-re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   101
        im_root[1]=re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   102
        re_root[2]=-re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   103
        im_root[2]=-re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   104
        re_root[3]=re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   105
        im_root[3]=-re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   106
        if(PRINT_DEBUG) System.err.println("Path a=0 d>0");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   107
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   108
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   109
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   110
        final double sq4 = Math.sqrt(Math.sqrt(-d));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   111
        re_root[0]=sq4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   112
        im_root[0]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   113
        re_root[1]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   114
        im_root[1]=sq4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   115
        re_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   116
        im_root[2]=-sq4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   117
        re_root[3]=-sq4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   118
        im_root[3]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   119
        if(PRINT_DEBUG) System.err.println("Path a=0 d<0");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   120
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   121
    return 4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   122
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   123
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   124
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   125
  if (0.0 == c && 0.0 == d)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   126
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   127
      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
   128
      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
   129
      return 4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   130
  }
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
  if(PRINT_DEBUG) System.err.println("G Path c="+c+" d="+d);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   133
  final double [] u=new double[3];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   134
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   135
  if(PRINT_DEBUG) System.err.println("Generic Path");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   136
  /* For non-degenerate solutions, proceed by constructing and
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   137
   * solving the resolvent cubic */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   138
  final double aa = a * a;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   139
  final double pp = b - q1 * aa;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   140
  final double qq = c - q2 * a * (b - q4 * aa);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   141
  final double rr = d - q4 * a * (c - q4 * a * (b - q3 * aa));
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   142
  final double rc = q2 * pp , rc3 = rc / 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   143
  final double sc = q4 * (q4 * pp * pp - rr);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   144
  final double tc = -(q8 * qq * q8 * qq);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   145
  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
   146
  final boolean flag_realroots;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   147
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   148
  /* This code solves the resolvent cubic in a convenient fashion
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   149
   * for this implementation of the quartic. If there are three real
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   150
   * roots, then they are placed directly into u[].  If two are
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   151
   * 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
   152
   * and imaginary part of the complex roots are placed into
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   153
   * u[1] and u[2], respectively. */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   154
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   155
      final double qcub = (rc * rc - 3 * sc);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   156
      final double rcub = (rc*(2 * rc * rc - 9 * sc) + 27 * tc);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   157
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   158
      final double Q = qcub / 9;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   159
      final double R = rcub / 54;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   160
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   161
      final double Q3 = Q * Q * Q;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   162
      final double R2 = R * R;
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 CR2 = 729 * rcub * rcub;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   165
      final double CQ3 = 2916 * qcub * qcub * qcub;
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
      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
   168
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   169
      if (0 == R && 0 == Q)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   170
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   171
    flag_realroots=true;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   172
    u[0] = -rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   173
    u[1] = -rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   174
    u[2] = -rc3;
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
      else if (CR2 == CQ3)
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
    flag_realroots=true;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   179
    final double sqrtQ = Math.sqrt (Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   180
    if (R > 0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   181
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   182
        u[0] = -2 * sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   183
        u[1] = sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   184
        u[2] = sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   185
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   186
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   187
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   188
        u[0] = -sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   189
        u[1] = -sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   190
        u[2] = 2 * sqrtQ - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   191
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   192
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   193
      else if (R2 < Q3)
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
    flag_realroots=true;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   196
    final double ratio = (R >= 0?1:-1) * Math.sqrt (R2 / Q3);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   197
    final double theta = Math.acos (ratio);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   198
    final double norm = -2 * Math.sqrt (Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   199
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   200
    u[0] = norm * Math.cos (theta / 3) - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   201
    u[1] = norm * Math.cos ((theta + 2.0 * Math.PI) / 3) - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   202
    u[2] = norm * Math.cos ((theta - 2.0 * Math.PI) / 3) - rc3;
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
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   205
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   206
    flag_realroots=false;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   207
    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
   208
    final double B = Q / A;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   209
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   210
    u[0] = A + B - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   211
    u[1] = -0.5 * (A + B) - rc3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   212
    u[2] = -(SQRT3*0.5) * Math.abs (A - B);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   213
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   214
      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
   215
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   216
  /* End of solution to resolvent cubic */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   217
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   218
  /* Combine the square roots of the roots of the cubic
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   219
   * resolvent appropriately. Also, calculate 'mt' which
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   220
   * designates the nature of the roots:
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   221
   * mt=1 : 4 real roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   222
   * mt=2 : 0 real roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   223
   * mt=3 : 2 real roots
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
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
  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
   228
  if (flag_realroots)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   229
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   230
      mod_w1w2=-1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   231
      mt = 2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   232
      int jmin=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   233
      double vmin=Math.abs(u[jmin]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   234
      for(int j=1;j<3;j++)
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 vx=Math.abs(u[j]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   237
    if(vx<vmin)
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
        vmin=vx;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   240
        jmin=j;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   241
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   242
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   243
      final double u1=u[(jmin+1)%3],u2=u[(jmin+2)%3];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   244
      mod_w1w2_squared=Math.abs(u1*u2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   245
      if(u1>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   246
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   247
    w1_re=Math.sqrt(u1);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   248
    w1_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   249
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   250
      else
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
    w1_re=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   253
    w1_im=Math.sqrt(-u1);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   254
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   255
      if(u2>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   256
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   257
    w2_re=Math.sqrt(u2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   258
    w2_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   259
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   260
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   261
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   262
    w2_re=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   263
    w2_im=Math.sqrt(-u2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   264
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   265
      if(PRINT_DEBUG) System.err.println("u1="+u1+" u2="+u2+" jmin="+jmin);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   266
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   267
  else
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
      mt = 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   270
      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
   271
      if(w_mod2_sq<=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   272
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   273
    w1_re=w1_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   274
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   275
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   276
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   277
    // calculate square root of a complex number (u[1],u[2])
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   278
    // the result is in the (w1_re,w1_im)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   279
    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
   280
    if(absu1>=absu2)
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
        final double t=absu2/absu1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   283
        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
   284
        if(PRINT_DEBUG) System.err.println(" Path1 ");
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
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   287
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   288
        final double t=absu1/absu2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   289
        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
   290
        if(PRINT_DEBUG) System.err.println(" Path1a ");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   291
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   292
    if(u[1]>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   293
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   294
        w1_re=w;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   295
        w1_im=u[2]/(2*w);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   296
        if(PRINT_DEBUG) System.err.println(" Path2 ");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   297
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   298
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   299
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   300
        final double vi = (u[2] >= 0) ? w : -w;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   301
        w1_re=u[2]/(2*vi);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   302
        w1_im=vi;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   303
        if(PRINT_DEBUG) System.err.println(" Path2a ");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   304
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   305
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   306
      final double absu0=Math.abs(u[0]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   307
      if(w_mod2>=absu0)
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
    mod_w1w2=w_mod2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   310
    mod_w1w2_squared=w_mod2_sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   311
    w2_re=w1_re;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   312
    w2_im=-w1_im;
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
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   315
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   316
    mod_w1w2=-1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   317
    mod_w1w2_squared=w_mod2*absu0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   318
    if(u[0]>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   319
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   320
        w2_re=Math.sqrt(absu0);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   321
        w2_im=0;
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
        w2_re=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   326
        w2_im=Math.sqrt(absu0);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   327
    }
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
      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
   330
  }
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
  /* Solve the quadratic in order to obtain the roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   333
   * to the quartic */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   334
  if(mod_w1w2>0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   335
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   336
      // a shorcut to reduce rounding error
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   337
      w3_re=qq/(-8)/mod_w1w2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   338
      w3_im=0;
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
  else if(mod_w1w2_squared>0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   341
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   342
      // regular path
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   343
      final double mqq8n=qq/(-8)/mod_w1w2_squared;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   344
      w3_re=mqq8n*(w1_re*w2_re-w1_im*w2_im);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   345
      w3_im=-mqq8n*(w1_re*w2_im+w2_re*w1_im);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   346
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   347
  else
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
      // typically occur when qq==0
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   350
      w3_re=w3_im=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   351
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   352
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   353
  final double h = r4 * a;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   354
  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
   355
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   356
  re_root[0]=w1_re+w2_re+w3_re-h;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   357
  im_root[0]=w1_im+w2_im+w3_im;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   358
  re_root[1]=-(w1_re+w2_re)+w3_re-h;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   359
  im_root[1]=-(w1_im+w2_im)+w3_im;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   360
  re_root[2]=w2_re-w1_re-w3_re-h;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   361
  im_root[2]=w2_im-w1_im-w3_im;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   362
  re_root[3]=w1_re-w2_re-w3_re-h;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   363
  im_root[3]=w1_im-w2_im-w3_im;
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
  return 4;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   366
}
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   367
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   368
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   369
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   370
    static void setRandomP(final double [] p,final int n,java.util.Random r)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   371
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   372
  if(r.nextDouble()<0.1)
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
      // integer coefficiens
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   375
      for(int j=0;j<p.length;j++)
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
    if(j<=n)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   378
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   379
        p[j]=(r.nextInt(2)<=0?-1:1)*r.nextInt(10);
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
    else
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
        p[j]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   384
    }
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
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   387
  else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   388
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   389
      // real coefficiens
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   390
      for(int j=0;j<p.length;j++)
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
    if(j<=n)
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
        p[j]=-1+2*r.nextDouble();
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
        p[j]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   399
    }
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
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   402
  if(Math.abs(p[n])<1e-2)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   403
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   404
      p[n]=(r.nextInt(2)<=0?-1:1)*(0.1+r.nextDouble());
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   405
  }
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
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
    static void checkValues(final double [] p,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   410
          final int n,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   411
          final double rex,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   412
          final double imx,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   413
          final double eps,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   414
          final String txt)
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
  double res=0,ims=0,sabs=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   417
  final double xabs=Math.abs(rex)+Math.abs(imx);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   418
  for(int k=n;k>=0;k--)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   419
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   420
      final double res1=(res*rex-ims*imx)+p[k];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   421
      final double ims1=(ims*rex+res*imx);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   422
      res=res1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   423
      ims=ims1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   424
      sabs+=xabs*sabs+p[k];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   425
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   426
  sabs=Math.abs(sabs);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   427
  if(false && sabs>1/eps?
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   428
     (!(Math.abs(res/sabs)<=eps)||!(Math.abs(ims/sabs)<=eps))
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   429
     :
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   430
     (!(Math.abs(res)<=eps)||!(Math.abs(ims)<=eps)))
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   431
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   432
      throw new RuntimeException(
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   433
    getPolinomTXT(p)+"\n"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   434
    "\t x.r="+rex+" x.i="+imx+"\n"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   435
    "res/sabs="+(res/sabs)+" ims/sabs="+(ims/sabs)+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   436
    " sabs="+sabs+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   437
    "\nres="+res+" ims="+ims+" n="+n+" eps="+eps+" "+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   438
    " sabs>1/eps="+(sabs>1/eps)+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   439
    " f1="+(!(Math.abs(res/sabs)<=eps)||!(Math.abs(ims/sabs)<=eps))+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   440
    " f2="+(!(Math.abs(res)<=eps)||!(Math.abs(ims)<=eps))+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   441
    " "+txt);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   442
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   443
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   444
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   445
    static String getPolinomTXT(final double [] p)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   446
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   447
  final StringBuilder buf=new StringBuilder();
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   448
  buf.append("order="+(p.length-1)+"\t");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   449
  for(int k=0;k<p.length;k++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   450
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   451
      buf.append("p["+k+"]="+p[k]+";");
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
  return buf.toString();
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   454
    }
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
    static String getRootsTXT(int nr,final double [] re,final double [] im)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   457
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   458
  final StringBuilder buf=new StringBuilder();
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   459
  for(int k=0;k<nr;k++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   460
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   461
      buf.append("x."+k+"("+re[k]+","+im[k]+")\n");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   462
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   463
  return buf.toString();
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
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   466
    static void testRoots(final int n,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   467
        final int n_tests,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   468
        final java.util.Random rn,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   469
        final double eps)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   470
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   471
  final double [] p=new double [n+1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   472
  final double [] rex=new double [n],imx=new double [n];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   473
  for(int i=0;i<n_tests;i++)
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
    for(int dg=n;dg-->-1;)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   476
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   477
      for(int dr=3;dr-->0;)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   478
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   479
        setRandomP(p,n,rn);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   480
        for(int j=0;j<=dg;j++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   481
        {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   482
      p[j]=0;
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
        if(dr==0)
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
      p[0]=-1+2.0*rn.nextDouble();
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
        else if(dr==1)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   489
        {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   490
      p[0]=p[1]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   491
        }
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
        findPolynomialRoots(n,p,rex,imx);
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
        for(int j=0;j<n;j++)
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
      //System.err.println("j="+j);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   498
      checkValues(p,n,rex[j],imx[j],eps," t="+i);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   499
        }
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
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   503
  System.err.println("testRoots(): n_tests="+n_tests+" OK, dim="+n);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   504
    }
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
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   507
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
    static final double EPS=0;
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
    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
   512
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   513
  if(!(Math.abs(p[1])>EPS))
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
      re_root[0]=im_root[0]=Double.NaN;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   516
      return -1;
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
  re_root[0]=-p[0]/p[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   519
  im_root[0]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   520
  return 1;
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
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   523
    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
   524
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   525
  if(!(Math.abs(p[2])>EPS))
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]=re_root[1]=im_root[0]=im_root[1]=Double.NaN;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   528
      return -1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   529
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   530
  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
   531
  if(d>=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   532
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   533
      final double sq=Math.sqrt(d);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   534
      if(b2<0)
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[1]=-b2+sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   537
    re_root[0]=c/re_root[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
      else if(b2>0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   540
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   541
    re_root[0]=-b2-sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   542
    re_root[1]=c/re_root[0];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   543
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   544
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   545
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   546
    re_root[0]=-b2-sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   547
    re_root[1]=-b2+sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   548
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   549
      im_root[0]=im_root[1]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   550
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   551
  else
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
      final double sq=Math.sqrt(-d);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   554
      re_root[0]=re_root[1]=-b2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   555
      im_root[0]=sq;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   556
      im_root[1]=-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
  return 2;
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
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   561
    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
   562
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   563
  final double vs=p[3];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   564
  if(!(Math.abs(vs)>EPS))
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   565
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   566
      re_root[0]=re_root[1]=re_root[2]=
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   567
    im_root[0]=im_root[1]=im_root[2]=Double.NaN;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   568
      return -1;
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
  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
   571
  /* 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
   572
   */
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   573
  final double q = (a * a - 3 * b);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   574
  final double r = (a*(2 * a * a - 9 * b) + 27 * c);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   575
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   576
  final double Q = q / 9;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   577
  final double R = r / 54;
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 Q3 = Q * Q * Q;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   580
  final double R2 = R * R;
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 CR2 = 729 * r * r;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   583
  final double CQ3 = 2916 * q * q * q;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   584
  final double a3=a/3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   585
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   586
  if (R == 0 && Q == 0)
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
      re_root[0]=re_root[1]=re_root[2]=-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   589
      im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   590
      return 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   591
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   592
  else if (CR2 == CQ3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   593
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   594
      /* this test is actually R2 == Q3, written in a form suitable
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   595
         for exact computation with integers */
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
      /* Due to finite precision some double roots may be missed, and
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   598
         will be considered to be a pair of complex roots z = x +/-
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   599
         epsilon i close to the real axis. */
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
      final double sqrtQ = Math.sqrt (Q);
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
      if (R > 0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   604
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   605
    re_root[0] = -2 * sqrtQ - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   606
    re_root[1]=re_root[2]=sqrtQ - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   607
    im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   608
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   609
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   610
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   611
    re_root[0]=re_root[1] = -sqrtQ - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   612
    re_root[2]=2 * sqrtQ - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   613
    im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   614
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   615
      return 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   616
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   617
  else if (R2 < Q3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   618
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   619
      final double sgnR = (R >= 0 ? 1 : -1);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   620
      final double ratio = sgnR * Math.sqrt (R2 / Q3);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   621
      final double theta = Math.acos (ratio);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   622
      final double norm = -2 * Math.sqrt (Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   623
      final double r0 = norm * Math.cos (theta/3) - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   624
      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
   625
      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
   626
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   627
      re_root[0]=r0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   628
      re_root[1]=r1;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   629
      re_root[2]=r2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   630
      im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   631
      return 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   632
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   633
  else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   634
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   635
      final double sgnR = (R >= 0 ? 1 : -1);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   636
      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
   637
      final double B = Q / A;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   638
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   639
      re_root[0]=A + B - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   640
      im_root[0]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   641
      re_root[1]=-0.5 * (A + B) - a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   642
      im_root[1]=-(SQRT3*0.5) * Math.abs(A - B);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   643
      re_root[2]=re_root[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   644
      im_root[2]=-im_root[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   645
      return 3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   646
  }
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
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   649
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   650
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   651
    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
   652
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   653
  if(Math.abs(p[3])>EPS)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   654
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   655
      final double v=p[3],
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   656
    a=p[2]/v,b=p[1]/v,c=p[0]/v,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   657
    a3=a/3,a3a=a3*a,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   658
    pd3=(b-a3a)/3,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   659
    qd2=a3*(a3a/3-0.5*b)+0.5*c,
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   660
    Q=pd3*pd3*pd3+qd2*qd2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   661
      if(Q<0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   662
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   663
    // three real roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   664
    final double SQ=Math.sqrt(-Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   665
    final double th=Math.atan2(SQ,-qd2);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   666
    im_root[0]=im_root[1]=im_root[2]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   667
    final double f=2*Math.sqrt(-pd3);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   668
    re_root[0]=f*Math.cos(th/3)-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   669
    re_root[1]=f*Math.cos((th+2*Math.PI)/3)-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   670
    re_root[2]=f*Math.cos((th+4*Math.PI)/3)-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   671
    //System.err.println("3r");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   672
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   673
      else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   674
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   675
    // one real & two complex roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   676
    final double SQ=Math.sqrt(Q);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   677
    final double r1=-qd2+SQ,r2=-qd2-SQ;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   678
    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
   679
        v2=Math.signum(r2)*Math.pow(Math.abs(r2),1.0/3),
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   680
        sv=v1+v2;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   681
    // real root
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   682
    re_root[0]=sv-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   683
    im_root[0]=0;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   684
    // complex roots
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   685
    re_root[1]=re_root[2]=-0.5*sv-a3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   686
    im_root[1]=(v1-v2)*(SQRT3*0.5);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   687
    im_root[2]=-im_root[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   688
    //System.err.println("1r2c");
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   689
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   690
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   691
  else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   692
  {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   693
      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
   694
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   695
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   696
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   697
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   698
    static void printSpecialValues()
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
  for(int st=0;st<6;st++)
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
      //final double [] p=new double []{8,1,3,3.6,1};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   703
      final double [] re_root=new double [4],im_root=new double [4];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   704
      final double [] p;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   705
      final int n;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   706
      if(st<=3)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   707
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   708
    if(st<=0)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   709
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   710
        p=new double []{2,-4,6,-4,1};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   711
        //p=new double []{-6,6,-6,8,-2};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   712
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   713
    else if(st==1)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   714
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   715
        p=new double []{0,-4,8,3,-9};
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
    else if(st==2)
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 []{-1,0,2,0,-1};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   720
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   721
    else
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   722
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   723
        p=new double []{-5,2,8,-2,-3};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   724
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   725
    root4(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   726
    n=4;
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
      else
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
    p=new double []{0,2,0,1};
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   731
    if(st==4)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   732
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   733
        p[1]=-p[1];
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   734
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   735
    root3(p,re_root,im_root);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   736
    n=3;
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   737
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   738
      System.err.println("======== n="+n);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   739
      for(int i=0;i<=n;i++)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   740
      {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   741
    if(i<n)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   742
    {
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   743
        System.err.println(String.valueOf(i)+"\t"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   744
               p[i]+"\t"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   745
               re_root[i]+"\t"+
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   746
               im_root[i]);
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   747
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   748
    else
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
        System.err.println(String.valueOf(i)+"\t"+p[i]+"\t");
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
      }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   753
  }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   754
    }
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   755
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
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   758
    public static void main(final String [] args)
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   759
    {
18698
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   760
      if (System.getProperty("os.arch").equals("x86") ||
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   761
         System.getProperty("os.arch").equals("amd64") ||
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   762
         System.getProperty("os.arch").equals("x86_64")){
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   763
        final long t0=System.currentTimeMillis();
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   764
        final double eps=1e-6;
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   765
        //checkRoots();
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   766
        final java.util.Random r=new java.util.Random(-1381923);
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   767
        printSpecialValues();
18450
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
        final int n_tests=100000;
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   770
        //testRoots(2,n_tests,r,eps);
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   771
        //testRoots(3,n_tests,r,eps);
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   772
        testRoots(4,n_tests,r,eps);
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   773
        final long t1=System.currentTimeMillis();
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   774
        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
   775
        System.out.println("PASSED");
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   776
     } else {
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   777
       System.out.println("PASS test for non-x86");
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   778
     }
862c19338ded 8019625: Test compiler/8005956/PolynomialRoot.java timeouts on Solaris SPARCs
adlertz
parents: 18450
diff changeset
   779
   }
18450
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   780
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   781
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   782
cdbc4dcf2d85 8017510: Add a regression test for 8005956
adlertz
parents:
diff changeset
   783
}