• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Strange issue when converting from hex to float
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange issue when converting from hex to float


  • Subject: Re: Strange issue when converting from hex to float
  • From: Ian was here <email@hidden>
  • Date: Fri, 22 Jul 2005 10:00:01 -0700 (PDT)

I've tried all that before, and the result always
yields zero.


float			fBlue = (float)alphaComp / (float)255.0;
float			fBlue = (float)alphaComp / 255.0f;
float			fBlue = (float)alphaComp / 255.0L;


Thanks for trying.



--- Sherm Pendley <email@hidden> wrote:

> 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
>
>




____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

 _______________________________________________
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

  • Follow-Ups:
    • Re: Strange issue when converting from hex to float
      • From: Sherm Pendley <email@hidden>
    • Re: Strange issue when converting from hex to float
      • From: Nicko van Someren <email@hidden>
References: 
 >Re: Strange issue when converting from hex to float (From: Sherm Pendley <email@hidden>)

  • Prev by Date: Facsimile & Cocoa
  • Next by Date: changing the text color of disabled textfields
  • Previous by thread: Re: Strange issue when converting from hex to float
  • Next by thread: Re: Strange issue when converting from hex to float
  • Index(es):
    • Date
    • Thread