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

Crazy floats


  • Subject: Crazy floats
  • From: Lorenzo <email@hidden>
  • Date: Fri, 23 Jul 2004 15:27:13 +0200

Hi,
I have a floats with 3 values but if I add many times the value 0.2 to one
item, it gets some decimal value more. Instead of -0.693000, I get
-0.693001. Why do I get the 1 at the end?

float positions[3];

positions[0] = -0.693000; // currentPoint
positions[1] = positions[0] + 2; // endPoint
positions[2] = increment = 0.2; // increment

so I try to add the increment to the "currentPoint" value until it is equal
to the "end" value.

while(positions[0] != positions[1]){
positions[0] += positions[2];
NSLog(@"currentPoint %f, end %f, increm %f",
positions[0], positions[1], positions[2]);
}

And since they are never equal, this produces an "infinite loop" (I am not
speaking about the Apple address).


My log:
--------
currentPoint -2.693000, end -0.693000, increm 0.020000
...
currentPoint -0.693002, end -0.693000, increm 0.020000
currentPoint -0.673002, end -0.693000, increm 0.020000
...
currentPoint 0.006998, end -0.693000, increm 0.020000


Best Regards
--
Lorenzo
email: email@hidden
_______________________________________________
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.


  • Prev by Date: Re: Memory management, when mixing C and ObjC
  • Next by Date: Re: Memory management, when mixing C and ObjC
  • Previous by thread: Re: NSSpeechSynthesizer and Volume
  • Next by thread: Re: Crazy floats
  • Index(es):
    • Date
    • Thread