Ruby | BigDecimal class hash value

BigDecimal#hash() : hash() is a BigDecimal class method which returns the hash value for the BigDecimal value.

Syntax: BigDecimal.hash()

Parameter: BigDecimal values to find the hash part of the value



Return: hash value for the BigDecimal value

Code #1 : Example for hash() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for hash() method
  
# loading BigDecimal
require 'bigdecimal'
  
# declaring BigDecimal
a = 42.1**13
  
# declaring BigDecimal
b = -BigDecimal("10")
  
# declaring BigDecimal
c = -(22 ** 7.1) * 10
  
  
# a
puts "hash value of a : #{a.hash}\n\n"
  
# b
puts "hash value of b : #{b.hash}\n\n"
  
# c
puts "hash value of c : #{c.hash}\n\n"
     

chevron_right


Output :

hash value of a : -356173160844341091

hash value of b : -3967525242845538832

hash value of c : -3453672420229872218

Code #2 : Example for hash() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for hash() method
  
# loading BigDecimal
require 'bigdecimal'
  
# declaring BigDecimal
a = 12**12 - 27
  
# declaring BigDecimal
b = BigDecimal('10')-(22 ** 7.1) ** 10
  
# declaring BigDecimal
c = BigDecimal('-3')
  
# a
puts "hash value of a : #{a.hash}\n\n"
  
# b
puts "hash value of b : #{b.hash}\n\n"
  
# c
puts "hash value of c : #{c.hash}\n\n"

chevron_right


Output :

hash value of a : -3561916586715218903

hash value of b : 1852347221456838115

hash value of c : 1714082193134741719



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.