📜  带有示例的 Scala Float signum() 方法

📅  最后修改于: 2022-05-13 01:55:15.145000             🧑  作者: Mango

带有示例的 Scala Float signum() 方法

signum()方法用于为指定的正数返回 1,为指定的负数返回 -1,为指定的 0 值返回 0。

示例 #1:

// Scala program of Float signum()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying signum method
        val result = (5).signum
          
        // Displays output
        println(result)
      
    }
} 
输出:
1

示例 #2:

// Scala program of Float signum()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying signum method
        val result = (-5).signum
          
        // Displays output
        println(result)
      
    }
} 
输出:
-1

示例#3:

// Scala program of Float signum()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
      
        // Applying signum method
        val result = (0).signum
          
        // Displays output
        println(result)
      
    }
} 
输出:
0