• 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: Can't divide integers ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't divide integers ?


  • Subject: Re: Can't divide integers ?
  • From: Óscar Morales Vivó <email@hidden>
  • Date: Wed, 21 Jul 2004 20:39:10 +0200

Well, you'd need something like the following:

- (void)myMethod
{
unsigned a = 50;
unsigned b = 100;

float c = (float)a / (float)b;

...
}

Otherwise it does integer division, which for 50/100 equals 0.

It's a pretty annoying part of C if you ask me, but you get used to it.

On 21 Jul 2004, at 20:26, Eric Morand wrote:

Hi to all,

Here is a strange problem I have.

I want to divide two integers, giving a float.

Here is what I do :

- (void)myMethod
{
unsigned a = 50;
unsigned b = 100;

float c = a/b;

...
}

If I check in the debugger, c is equal to zero !!!

If I write :

- (void)myMethod
{
float a = 50;
float b = 100;

float c = a/b;

...
}

It works !!!



What does this mean ? Is it impossible to divide two integers ?

_______________________________________________
MacOSX-dev mailing list
email@hidden
http://www.omnigroup.com/mailman/listinfo/macosx-dev
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Can't divide integers ?
      • From: Scott Thompson <email@hidden>
  • Prev by Date: Re: Writing pure java cocoa applications
  • Next by Date: Re: Using NSStream fails
  • Previous by thread: Association with an url only while my app is running
  • Next by thread: Re: Can't divide integers ?
  • Index(es):
    • Date
    • Thread