Open In App

Ruby | Math log10() function

Improve
Improve
Like Article
Like
Save
Share
Report

The log10() function in Ruby returns the base 10 logarithm value of X.

Syntax: Math.log10(X)

Parameter: The function takes one mandatory parameter X whose base 10 logarithm value is to be returned.

Return Value: The function the base 10 logarithm value of X.

Example 1:




# Ruby program for log10() function 
  
# Assigning values
val1 = 213
val2 = 256
val3 = 27 
val4 = 100 
  
# Prints the value returned by log10() 
puts Math.log10(val1)
  
puts Math.log10(val2)
  
puts Math.log10(val3)
  
puts Math.log10(val4)


Output:

2.3283796034387376
2.4082399653118496
1.4313637641589874
2.0

Example 2:




# Ruby program for log10() function 
  
# Assigning values
val1 = 21
val2 = 2
val3 = 19
val4 = 121
  
# Prints the value returned by log10() 
puts Math.log10(val1)
  
puts Math.log10(val2)
  
puts Math.log10(val3)
  
puts Math.log10(val4)


Output:

1.3222192947339193
0.3010299956639812
1.2787536009528289
2.08278537031645

Reference: https://devdocs.io/ruby~2.5/math#method-c-log10



Last Updated : 07 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads