Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

signum
java
strictmath
communitycreator

What is the StrictMath.signum(float) function in Java?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

In Java, signum is a static function of the StrictMath class. It is used to get the signum function of the specified float value.

Note: The StrictMath class has some utility methods for performing basic numeric operations. It is present in the java.lang package. Read more about the StrictMath class here.

Syntax

public static float signum(float d)

Parameter value

This method takes a float value as an argument.

Return value

This method returns a float value:

  • 1.0: The argument is greater than zero.

  • -1.0: The argument is less than zero.

  • 0.0: The argument is equal to zero.

Note: If the argument is NaN, +0.0, or -0.0, the return value is the same as the argument.

Code

class SignumExample {
public static void main(String[] args) {
System.out.println("Signum for -10.10f is " + StrictMath.signum(-10.10f));
System.out.println("Signum for 10.5f is " + StrictMath.signum(10.5f));
System.out.println("Signum for 0.0f is " + StrictMath.signum(0.0f));
}
}
Using StrictMath.signum method

Explanation

  • Line 3:, We call the StrictMath.signum(-10.10f) function. This returns -1.0 because the argument is less than zero.

  • Line 4: We call the StrictMath.signum(10.5f) function. This returns 1.0 because the argument is greater than zero.

  • Line 5: We call the StrictMath.signum(0.0f) function. This returns 0.0 because the argument is equal to zero.

RELATED TAGS

signum
java
strictmath
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring