Java sin sin_v2(double x)

Here you can find the source of sin_v2(double x)

Description

siv

License

Apache License

Declaration

static public double sin_v2(double x) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2011 See AUTHORS file./*from  ww w. ja  v  a2 s  .  c  o m*/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

public class Main {
    static private final int BIG_ENOUGH_INT = 16 * 1024;
    static private final double BIG_ENOUGH_FLOOR = BIG_ENOUGH_INT;

    static public double sin_v2(double x) {
        double q, t;
        int quadrant;
        /* Cody-Waite style argument reduction */
        q = rint_v2(x * 6.3661977236758138e-1);
        quadrant = (int) q;
        t = x - q * 1.5707963267923333e+00;
        t = t - q * 2.5633441515945189e-12;
        if ((quadrant & 1) != 0) {
            t = cos_core(t);
        } else {
            t = sin_core(t);
        }
        return ((quadrant & 2) != 0) ? -t : t;
    }

    static public double rint_v2(double x) {
        double t = floor(Math.abs(x) + 0.5);
        return (x < 0.0) ? -t : t;
    }

    static public double cos_core(double x) {
        double x8, x4, x2;
        x2 = x * x;
        x4 = x2 * x2;
        x8 = x4 * x4;
        /* evaluate polynomial using Estrin's scheme */
        return (-2.7236370439787708e-7 * x2 + 2.4799852696610628e-5) * x8
                + (-1.3888885054799695e-3 * x2 + 4.1666666636943683e-2) * x4
                + (-4.9999999999963024e-1 * x2 + 1.0000000000000000e+0);
    }

    static public double sin_core(double x) {
        double x4, x2;
        x2 = x * x;
        x4 = x2 * x2;
        /* evaluate polynomial using a mix of Estrin's and Horner's scheme */
        return ((2.7181216275479732e-6 * x2 - 1.9839312269456257e-4) * x4
                + (8.3333293048425631e-3 * x2 - 1.6666666640797048e-1)) * x2 * x + x;
    }

    /** Returns the largest integer less than or equal to the specified double. This method will only properly floor doubles from
     * -(2^14) to (Float.MAX_VALUE - 2^14). */
    static public int floor(double x) {
        return (int) (x + BIG_ENOUGH_FLOOR) - BIG_ENOUGH_INT;
    }
}

Related

  1. sin(int i)
  2. sin(Number x)
  3. sin(Short a)
  4. sin5(float x)
  5. sin_core(double x)
  6. sind(double degreeAngle)
  7. sinDeg(double degrees)
  8. sinDegrees(double angleInDegrees)
  9. sinf(float f)