Open In App

Ruby | BigDecimal class hash value

Last Updated : 08 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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




# 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"
     


Output :

hash value of a : -356173160844341091

hash value of b : -3967525242845538832

hash value of c : -3453672420229872218

Code #2 : Example for hash() method




# 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"


Output :

hash value of a : -3561916586715218903

hash value of b : 1852347221456838115

hash value of c : 1714082193134741719


Similar Reads

Ruby | BigDecimal class floor value
BigDecimal#floor() : floor() is a BigDecimal class method which return the floor value of the passed BigDecimal value. Syntax: BigDecimal.floor() Parameter: - BigDecimal value which is to get its floor value - decimal digits (default = 0) Return: - smallest number >= to BigDecimal with a ndigits decimal point precision. - For -ve precision : Int
2 min read
Ruby | BigDecimal class power value
BigDecimal#power() : power() is a BigDecimal class method which returns the BigDecimal value raised to the power of n. Syntax: BigDecimal.power() Parameter: BigDecimal values to find the power the value Return: n - value raised to the power of n prec - precision Code #1 : Example for power() method # Ruby code for power() method # loading BigDecima
1 min read
Ruby | BigDecimal class nonzero? value
BigDecimal#nonzero?() : nonzero?() is a BigDecimal class method which checks whether the BigDecimal value is nonzero. Syntax: BigDecimal.nonzero?() Parameter: BigDecimal values to check Return: self : if value is nonzero; otherwise nil Code #1 : Example for nonzero?() method # Ruby code for nonzero?() method # loading BigDecimal require 'bigdecimal
1 min read
Ruby | BigDecimal class nan? value
BigDecimal#nan?() : nan?() is a BigDecimal class method which checks whether the BigDecimal value is nan value. Syntax: BigDecimal.nan?() Parameter: BigDecimal values to check regarding the NaN value. Return: true : if value is a NaN value; otherwise false Code #1 : Example for nan?() method # Ruby code for nan?() method # loading BigDecimal requir
1 min read
Ruby | BigDecimal class modulo value
BigDecimal#modulo() : modulo() is a BigDecimal class method which returns the modulus from dividing two BigDecimal values. Syntax: BigDecimal.modulo() Parameter: BigDecimal values to divide Return: modulus from dividing two BigDecimal values Code #1 : Example for modulo() method # Ruby code for modulo() method # loading BigDecimal require 'bigdecim
1 min read
Ruby | BigDecimal class inspect value
BigDecimal#inspect() : inspect() is a BigDecimal class method which returns debugging information about the value as a string of comma-separated values . Syntax: BigDecimal.inspect() Parameter: BigDecimal values to find the inspect the value Return: first part - the address second - value as a string final part - current and maximum number of signi
2 min read
Ruby | BigDecimal fix class value
BigDecimal#fix() : fix() is a BigDecimal class method which returns the integer value for the BigDecimal value. Syntax: BigDecimal.fix() Parameter: BigDecimal values to find the integer value Return: integer value for the BigDecimal value Code #1 : Example for fix() method # Ruby code for fix() method # loading BigDecimal require 'bigdecimal' # dec
1 min read
Ruby | BigDecimal class frac value
BigDecimal#frac() : frac() is a BigDecimal class method which returns the fractional value for the BigDecimal value. Syntax: BigDecimal.frac() Parameter: BigDecimal values to find the fractional part of the value Return: integer value for the BigDecimal value Code #1 : Example for frac() method # Ruby code for frac() method # loading BigDecimal req
1 min read
Ruby | BigDecimal class exponent value
BigDecimal#exponent() : exponent() is a BigDecimal class method which returns the exponent value for the BigDecimal value. Syntax: BigDecimal.exponent() Parameter: BigDecimal values to find the exponent value Return: exponent value for the BigDecimal value Code #1 : Example for exponent() method # Ruby code for exponent() method # loading BigDecima
1 min read
Ruby | BigDecimal class dup value
BigDecimal#dup() : dup() is a BigDecimal class method which returns the duplicate value for the BigDecimal value. Syntax: BigDecimal.dup() Parameter: BigDecimal values to find the duplicate value Return: duplicate value for the BigDecimal value Code #1 : Example for dup() method # Ruby code for dup() method # loading BigDecimal require 'bigdecimal'
1 min read