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


Ruby Math tan()用法及代碼示例


tan()是Ruby中的內置函數,返回以弧度表示的給定角度的正切值,其範圍為[-inf,+ inf]。返回的值在[-inf,+ inf]範圍內。

用法:Math.tan(value) 

參數:該函數接受一個強製性參數值,其返回相應的切線值。


返回值:返回切線值。

例子1

#Ruby program for tan() function 
  
#Assigning values 
val1 = 1 val2 = 0 val3 = 989 val4 = -8932 
  
#Prints the tan() value 
                                     puts Math.tan(val1) 
                                         puts Math.tan(val2) 
                                             puts Math.tan(val3) 
                                                 puts Math.tan(val4)

輸出

1.5574077246549023
0.0
-0.6866146142998235
-0.48563022371184766

例子2

#Ruby program for tan() function 
  
#Assigning values 
val1 = -1023 val2 = 0.67 val3 = 98 val4 = -39 
  
#Prints the tan() value 
                                           puts Math.tan(val1) 
                                               puts Math.tan(val2) 
                                                   puts Math.tan(val3) 
                                                       puts Math.tan(val4)

輸出

2.290822861412639
0.7922541747282569
0.6998536538095259
-3.614554407101535

參考:https://devdocs.io/ruby~2.5/math#method-c-tan



相關用法


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