Floating point arithmetic Flashcards
What is the main difference between integer and floating point arithmetic?
a) Integer arithmetic does not allow negative values
b) Floating point arithmetic includes decimal precision
c) Integer arithmetic uses more memory
d) Floating point arithmetic uses only base-10 numbers
b) Floating point arithmetic includes decimal precision
What term refers to the degree of correctness in floating point operations?
a) Precision
b) Clarity
c) Accuracy
d) Scope
c) Accuracy
What is a key limitation of floating point arithmetic in computer systems?
a) It has unlimited precision
b) It only supports whole numbers
c) It introduces approximation due to binary representation
d) It cannot represent negative numbers
c) It introduces approximation due to binary representation
What is the binary representation of the decimal number 0.1?
a) 0.1
b) 0.001
c) 0.000110011001100110011001100110011
d) 0.100000001
c) 0.000110011001100110011001100110011
What causes decimal fractions like 0.1 and 0.2 to be approximations in binary?
a) Binary can only handle fractions with powers of 10
b) Binary lacks sufficient precision
c) Prime factors of decimal and binary systems differ
d) Binary numbers cannot handle fractions at all
c) Prime factors of decimal and binary systems differ
Why do 0.1f and 0.1d produce different results in Java?
a) They use different rounding methods
b) They are represented with different numbers of bits
c) They use different base systems
d) They are calculated with integer precision
b) They are represented with different numbers of bits
Which Java type allows the most precision for floating point numbers?
a) int
b) double
c) float
d) long
b) double
What is the purpose of the BigDecimal class in Java?
a) To handle complex numbers
b) To perform precise decimal calculations
c) To save memory
d) To simplify unit tests
b) To perform precise decimal calculations
What Java method rounds floating point numbers to the closest neighbor?
a) Math.round()
b) RoundingMode.HALF_UP
c) BigDecimal.add()
d) RoundingMode.CEILING
b) RoundingMode.HALF_UP
What is the purpose of the RoundingMode class in Java?
a) It converts integers to floats
b) It controls rounding behavior for BigDecimal
c) It increases float precision
d) It calculates square roots
b) It controls rounding behavior for BigDecimal
What is the default rounding mode for BigDecimal in Java?
a) UP
b) DOWN
c) HALF_UP
d) FLOOR
c) HALF_UP
What does the Java RoundingMode.CEILING setting do?
a) Rounds toward zero
b) Rounds toward positive infinity
c) Rounds toward negative infinity
d) Does not round
b) Rounds toward positive infinity
What does the RoundingMode.FLOOR setting do?
a) Rounds toward positive infinity
b) Rounds toward zero
c) Rounds toward negative infinity
d) Does not round
c) Rounds toward negative infinity
What is an advantage of using BigDecimal for financial calculations?
a) It is faster than double
b) It avoids floating point approximation errors
c) It uses less memory
d) It automatically formats currency
b) It avoids floating point approximation errors
What Java method is used to add BigDecimal numbers?
a) BigDecimal.add()
b) BigDecimal.plus()
c) BigDecimal.sum()
d) Math.addExact()
a) BigDecimal.add()