Java Number Sum sum(double x, double y)

Here you can find the source of sum(double x, double y)

Description

Calculates sum of two doubles, but treats NaNs as zeros.

License

Apache License

Parameter

Parameter Description
x First double
y Second double

Return

Sum(x,y) calculated as Double.isNaN(x)? y: Double.isNaN(y)? x: x + y;

Declaration

public static double sum(double x, double y) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from w  ww.ja  v a2  s  .  co  m
     * Calculates sum of two doubles, but treats NaNs as zeros.
     *
     * @param x First double
     * @param y Second double
     * @return Sum(x,y) calculated as <code>Double.isNaN(x)? y: Double.isNaN(y)? x: x + y;</code>
     */
    public static double sum(double x, double y) {
        return Double.isNaN(x) ? y : Double.isNaN(y) ? x : x + y;
    }
}

Related

  1. sum(double a, double b)
  2. sum(double start, double end, double step)
  3. sum(double x, double y)
  4. sum(final Iterable values)
  5. sum(final Iterable ns)
  6. sum(int a, int b)