Java Random Double getDoubleSpecial()

Here you can find the source of getDoubleSpecial()

Description

get Double Special

License

Apache License

Declaration

static double getDoubleSpecial() 

Method Source Code

//package com.java2s;
/*/* w  w  w .j  a  v a2s . c  om*/
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.
 */

import java.util.Random;

public class Main {
    static Random rng;
    static double[] dspecial = { 0, 1, 2, 4, 8, 256, 16384, 32768, 65536, .1, .25, Float.NEGATIVE_INFINITY,
            Float.POSITIVE_INFINITY, Float.MIN_VALUE, Float.MAX_VALUE, Double.NEGATIVE_INFINITY,
            Double.POSITIVE_INFINITY, Double.MIN_VALUE, Double.MAX_VALUE };

    static double getDoubleSpecial() {
        int i = rng.nextInt();
        long j = rng.nextLong();
        double f = Double.longBitsToDouble(j);
        if (f != f)
            f = 0; // get rid of NaN for comparison purposes
        if ((i & 0x10) != 0)
            return f;
        return dspecial[((int) j & 0x7fffffff) % dspecial.length] * ((i & 0x20) == 0 ? 1 : -1) + ((i & 0x03) - 1);
    }
}

Related

  1. generateRandomDoubleInRange(double min, double max)
  2. generateRandomLongitude()
  3. getDouble()
  4. getDouble()
  5. getDoubleInRange(double minValue, double maxValue)
  6. getRandomDouble()
  7. getRandomDouble(double min, double max)
  8. rand(double seed)
  9. randDouble()