Java Abs abs(double x)

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

Description

abs

License

Apache License

Declaration

public static double abs(double x) 

Method Source Code

//package com.java2s;
/*//from w w w. ja  v  a 2 s.c  o  m
 * Copyright 2008 Google Inc.
 *
 * 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 {
    public static double abs(double x) {
        // This is implemented this way so that either positive or negative
        // zeroes
        // get converted to positive zeros.
        // See http://www.concentric.net/~Ttwang/tech/javafloat.htm for details.
        return x <= 0 ? 0.0 - x : x;
    }

    public static float abs(float x) {
        return (float) abs((double) x);
    }

    public static int abs(int x) {
        return x < 0 ? -x : x;
    }

    public static long abs(long x) {
        return x < 0 ? -x : x;
    }
}

Related

  1. abs(double number)
  2. abs(double self)
  3. abs(double value)
  4. abs(double value)
  5. abs(double value)
  6. abs(double x)
  7. abs(double x)
  8. abs(double z)
  9. abs(double... values)