A faster floor implementation that Math.floor. - Java java.lang

Java examples for java.lang:Math Function

Description

A faster floor implementation that Math.floor.

Demo Code


//package com.java2s;

public class Main {
    /**//  w w w. j a  va 2  s . c o m
     * A faster floor implementation that Math.floor.
     * @param x The to floor value
     * @return The floored value
     */
    public static int fastFloor(double x) {
        int xi = (int) x;
        return x < xi ? xi - 1 : xi;
    }
}

Related Tutorials