當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Ruby Numeric rect()用法及代碼示例

rect()是Ruby中的內置方法,它返回一個由實數和虛數組成的數組。

用法: num.rect()

參數:該函數需要返回其實部和虛部的數字。


返回值:它返回一個由實數和虛數組成的數組。

例子1

# Ruby program for rect() 
# method in Numeric 
  
# Initialize a number  
num = Complex(10, 6) 
  
# Prints the rect part 
puts num.rect()

輸出

10
6

例子2

# Ruby program for rect() 
# method in Numeric 
  
# Initialize a number  
num = Complex(18, 16) 
  
# Prints the rect part 
puts num.rect()

輸出

18
16


相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Numeric rect() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。