Name: krT82822 Date: 10/13/99
Compile and run the following program. It prints out the double values after converting them to float. That part is not too hard.
Now run the program under jdb and print out the values of "f" before they are printed. You should get something like this:
------------------------
C:\javanew>jdb Junk
Initializing jdb...
> stop at Junk:11
Deferring breakpoint Junk:11.
It will be set after the class is loaded.
> run
run Junk
Java(TM) HotSpot Client VM warning: Setting of property "java.compiler" is ignor
ed
>
VM Started: Set deferred breakpoint request Junk:11
Breakpoint hit: thread="main", Junk.main(), line=11, bci=21
11 System.out.println("da[0] = " + f);
main[1] list
7 da[0] = 3.456712345d;
8 da[1] = 5.32178943d;
9
10 f = (float)da[0];
11 => System.out.println("da[0] = " + f);
12 f = (float)da[1];
13 System.out.println("da[1] = " + f);
14 }
15 }
main[1] next
main[1]
Breakpoint hit: thread="main", Junk.main(), line=11, bci=21
11 System.out.println("da[0] = " + f);
main[1] next
main[1] da[0] = 3.4567122
Step completed: thread="main", Junk.main(), line=12, bci=46
12 f = (float)da[1];
main[1] print f
f = 1.07985178E9
main[1]
----------------------------
Note that the value jdb gives for f is different than it's actual value by more that a little bit.
Here is the great program.
public class Junk
{
public static void main(String args[])
{
float f;
double da[] = new double[2];
da[0] = 3.456712345d;
da[1] = 5.32178943d;
f = (float)da[0];
System.out.println("da[0] = " + f);
f = (float)da[1];
System.out.println("da[1] = " + f);
}
}
(Review ID: 96005)
======================================================================
- duplicates
-
JDK-4259923 Incorrect values reported for locals of type long, float, and double
-
- Closed
-