step function

double step(
  1. double x
)

Heaviside step function.

x is the input value.

Specification: http://mathworld.wolfram.com/HeavisideStepFunction.html If x > 0, returns 1. If x == 0, returns 1/2. If x < 0, returns 0.

Example:

print(step(0.5));  // Output: 1

Implementation

double step(double x) {
  if (x > 0) return 1;
  if (x < 0) return 0;
  return 0.5;
}