Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Explain the behavior exhibited by the main method of the Subtraction class shown

ID: 3667206 • Letter: E

Question

Explain the behavior exhibited by the main method of the Subtraction class shown below. That is, explain why each print statement produces its result. Note that each print statement is identified by a letter (A through C) to facilitate writing your explanation. You must also include at least one citation of an authoritative reference that supports your explanation for any credit to be awarded. (Remember: Following the explanation, provide a reflection that addresses both your finding and your experience with this activity.)

Subtraction.java

Explanation / Answer

The byte, char, int, long types are fixed-point numbers, which are exact representions of numbers. Unlike fixed point numbers, floating point numbers will some times (safe to assume "most of the time") not be able to return an exact representation of a number.

When requiring a value that is exact, such as 1.5 or 150.1005, you'll want to use one of the fixed-point types, which will be able to represent the number exactly.

Basically what you need to worry about in floating point numbers is that there is a limited number of digits of precision. This can cause problems when testing for equality, or if your program actually needs more digits of precision than what that data type give you.The biggest is that you almost never want to compare two floating point numbers for equality (or inequality). You'll want to use greater than/less than comparisons instead.

As,

y = v1+v2 = 2.14748365E9

(y-64)-1 = 2.14748365E9

(y-65) = 2.14748352E9

(y-64) = 2.14748365E9

you can see the value stored of eacch expression in memory.

Of course, there are other means to store numbers when IEE754 isn't good enough. Libraries like Java's BigDecimal are available for most platforms and map well to SQL's number type. Symbols can be used for irrational numbers, and ratios that can't be accurately represented in binary or decimal floating point can be stored as a ratio.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote