浮點數phase()是一個浮點類方法,它對浮點值起作用,並且對正值和負值都起作用。
用法: float.phase()
參數:要檢查的浮點值
返回:返回0表示正值,否則返回pi(3.141592653589793)
範例1:
# Ruby code for phase() method
# Initializing value
a = -100.7 - 10.4
b = -100 * 2000.0
c = (22 + 7.1) * 4
# Printing result
puts "phase value of a:#{a.phase}\n\n"
puts "phase value of b:#{b.phase}\n\n"
puts "phase value of c:#{c.phase}\n\n"
輸出:
phase value of a:3.141592653589793 phase value of b:3.141592653589793 phase value of c:0
範例2:
# Ruby code for phase() method
# Initializing value
a = -56.23333333
b = 10000.0
c = -(22 + 7.1)
# Printing result
puts "phase value of a:#{a.phase}\n\n"
puts "phase value of b:#{b.phase}\n\n"
puts "phase value of c:#{c.phase}\n\n"
輸出:
phase value of a:3.141592653589793 phase value of b:0 phase value of c:3.141592653589793
相關用法
- Ruby Numeric phase()用法及代碼示例
- Ruby Float quo()用法及代碼示例
- Ruby Float eql()用法及代碼示例
- Ruby Float arg()用法及代碼示例
- Ruby Float zero?()用法及代碼示例
- Ruby Float nan?()用法及代碼示例
- Ruby Float coerce()用法及代碼示例
- Ruby Float denominator()用法及代碼示例
- Ruby Float to_r()用法及代碼示例
- Ruby Float absolute()用法及代碼示例
- Ruby Float angle()用法及代碼示例
- Ruby Float floor()用法及代碼示例
- Ruby Float ceil()用法及代碼示例
- Ruby Float round()用法及代碼示例
- Ruby Float positive()用法及代碼示例
注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby Float phase() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。