Re: Strange issue when converting from hex to float
Re: Strange issue when converting from hex to float
- Subject: Re: Strange issue when converting from hex to float
- From: Sherm Pendley <email@hidden>
- Date: Fri, 22 Jul 2005 12:20:04 -0400
On Jul 22, 2005, at 11:36 AM, Ian was here wrote:
Here's a copy of the offending method...thanks for
offering to take a look.
This was explained several times now - didn't you get *any* of the
responses?
Once again for the record:
long a = 5;
float b = a/255L;
Assignment (=) has a lower precedence than division (/), so the
division is performed first. Both 5 and 255L are longs, so no
conversion is necessary and an integer division is performed, with a
result of 0.
After the division is complete, the assignment takes place; at that
point a conversion is necessary to convert the integer result on the
right-hand side of the assignment so it can be stored in the float
variable on the left-hand side.
What you need to do is force the division to be done with floats; the
easiest way is to use a float constant:
float b = a/255.0;
You could also typecast one or both of the arguments to the division:
float b = (float)a/255L;
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden