Numeric Flashcards
What are the subclasses of numeric datatype?
Integer,Float,BigDecimal,Complex,Rational
In earlier versions of Ruby Integer further divided into two types? True or false
True - Fixnum and Bignum
Write the methods for
a) even check
b) odd check
c) zero check
d) integer check
n. even?
n. odd?
n. zero?
n. integer?
Write the methods to find gcd,lcm and both?
n. lcm
n. gcd
n. gcdlcm
Explain pred and succ methods
n. pred will print preceeder
n. succ will print successor
What are the methods related to fraction in float class?
Denominator and numerator
What round method will do in float class?
Either it will roundoff or roundup the nearest value
To print next high value , to print previous low value what are the methods used in Float?
ceil
float
What “quo” method will do in Rational?
It will perform division
What is the use of truncate method in BigDecimal?
It will truncate all the values after the dot and return integer value
Explain magnitude method in Rational?
same as abs method
How can you check the number is Positive or not?
positive? negative?
What is the use of abs2 method?
Complex(5).abs2 => gives square of the result
Explain conjugate method in Complex?
Complex(1, 2).conjugate #=> (1-2i)
How to get the imaginary part of complex numbers
Complex(9, -4).imaginary #=> -4