Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to use signum() to get the signum function of the argument, 0 if = 0, 1.0 if > 0 and -1.0 if < 0 in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {
 
    public static void main(String[] args) {
        
        double d1 = 3.14;
        double d2 = -1.87;
        double d3 = 0;
        double d4 = -0;
        
        // signum(double d)
        System.out.println("Math.signum(" + d1 + ") = " + Math.signum(d1));
        System.out.println("Math.signum(" + d2 + ") = " + Math.signum(d2));
        System.out.println("Math.signum(" + d3 + ") = " + Math.signum(d3));
        System.out.println("Math.signum(" + d4 + ") = " + Math.signum(d4));

    }
}
 
/*
run:

Math.signum(3.14) = 1.0
Math.signum(-1.87) = -1.0
Math.signum(0.0) = 0.0
Math.signum(0.0) = 0.0
 
*/

 



answered Sep 10, 2016 by avibootz
...