Java floor floor(final float val)

Here you can find the source of floor(final float val)

Description

Faster floor function.

License

Open Source License

Parameter

Parameter Description
val Value to floor

Return

Floored int value

Declaration

public static int floor(final float val) 

Method Source Code

//package com.java2s;
/**/*  w w w.j  av a2 s .c  o  m*/
 * Copyright (c) 2008-2012 Ardor Labs, Inc.
 *
 * This file is part of Ardor3D.
 *
 * Ardor3D is free software: you can redistribute it and/or modify it 
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or at <http://www.ardor3d.com/LICENSE>.
 */

public class Main {
    /**
     * Faster floor function. Does not handle NaN and Infinity. (Not handled when doing Math.floor and just casting
     * anyways, so question is if we want to handle it or not)
     * 
     * @param val
     *            Value to floor
     * @return Floored int value
     */
    public static int floor(final float val) {
        final int intVal = (int) val;
        return val < 0 ? val == intVal ? intVal : intVal - 1 : intVal;
    }

    /**
     * Faster floor function. Does not handle NaN and Infinity. (Not handled when doing Math.floor and just casting
     * anyways, so question is if we want to handle it or not)
     * 
     * @param val
     *            Value to floor
     * @return Floored long value
     */
    public static long floor(final double val) {
        final long longVal = (long) val;
        return val < 0 ? val == longVal ? longVal : longVal - 1 : longVal;
    }
}

Related

  1. floor(double x)
  2. floor(double x)
  3. floor(double x, double y)
  4. floor(double[] array)
  5. floor(final double num)
  6. floor(final float x)
  7. floor(float a)
  8. floor(float f)
  9. floor(float f)