• 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: confused about floats
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: confused about floats


  • Subject: Re: confused about floats
  • From: Murat Konar <email@hidden>
  • Date: Fri, 8 Oct 2010 12:05:33 -0700

A stripped down version of  your code works as expected here.


- (IBAction) test:(id) sender
{
    //set coordinates to x,y -> 0,0 to start
    float x = 0;
    float y = 0;

    while (YES) {

        NSLog(@"x = %f, y = %f", x, y);
        x = x+100;

        //if coordinates are too wide, start new row - if x>300, reset x to 0 and add 100 to y
        if(x > 300){
            x = 0;
            y = y+100;
        }
    }
}

I have in the past run into spooky code generation bugs.

<http://www.mailinglistarchive.com/email@hidden/msg07399.html>

I wonder if you've run into one too. Does it misbehave in both Debug and Release builds?

Also, are you sure x is getting past 300?

_murat


On Oct 5, 2010, at 2:07 AM, Amy Heavey wrote:

> I've got two float values (x and y) that I'm using to change the coordinates of a drawing action that is being looped through. I can add a value to x and it draws the next image along, but I want to test the value of x and if it is out of bounds I want to reset it to zero and increase y, so I get a grid of images drawn.
>
> For some reason, even though I can do
> x = x+128;
> and it moves the image accross, x seems to be null so I can't test against it, my if statement ' if (x > 300){' always fails.
>
> This must be something really simple I just can't see it this morning? I'd appreciate any help.
>
> Many Thanks
>
> Amy
>
> Full code being used:

[snipped]_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >confused about floats (From: Amy Heavey <email@hidden>)

  • Prev by Date: Re: Return value of performSelector:onThread:?
  • Next by Date: Re: confused about floats
  • Previous by thread: confused about floats
  • Next by thread: Re: confused about floats
  • Index(es):
    • Date
    • Thread