Results 1 to 3 of 3
- 08-11-2011, 01:23 AM #1
Possible loss of precision (short)
Hello, I've got a short variable which starts at 0, (I assign it at init() as "t = 0"); then, I add to it 0.01 (with "t = t + 0.01"). For some reason, when I compile, it gives me the error "possible loss of precision, found: double, required:short". Where's the error? Thanks!
- 08-11-2011, 01:58 AM #2
Did you try executing it and printing out the value of t after adding 0.01 to it?
The compiler generates code to do floating point arithmetic for the expression: t + 0.01
Then assigns the results to an int. What is the value of the expression?
What will be the value of the int? Will you lose any data?
The compiler is warning you about what happens.
- 08-14-2011, 03:04 AM #3
- By subith86 in forum New To JavaReplies: 1Last Post: 01-19-2011, 06:17 PM
- By jwb4291 in forum New To JavaReplies: 6Last Post: 12-02-2010, 05:28 AM
- By jankidudel in forum New To JavaReplies: 2Last Post: 08-07-2010, 10:15 AM
- By gandalf5166 in forum New To JavaReplies: 6Last Post: 04-13-2010, 08:21 PM
- By j2vdk in forum New To JavaReplies: 6Last Post: 09-01-2008, 09:23 AM