Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7566793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:30:14+00:00 2026-05-30T14:30:14+00:00

When I run this block of code : float angle = startAngle; int i

  • 0

When I run this block of code :

float angle = startAngle;
int i = 0;

for (float f = self.minNumber; f <= self.maxNumber; f += minorTickIncrement) {
    points[i++] = CGPointMake(centerX + cos(angle) * (radius - tickInset), centerY + sin(angle) * (radius - tickInset));

    CGFloat myTickLength;

    NSLog(@"f : %f",f);
    NSLog(@"tickIncrement : %f",tickIncrement);
    NSLog(@"f / tickIncrement : %f",f / tickIncrement);
    NSLog(@"(int)(f / tickIncrement) : %d",(int)(f / tickIncrement));
    NSLog(@"(f / tickIncrement - (int)(f / tickIncrement)) : %f",(f / tickIncrement - (int)(f / tickIncrement)));
    NSLog(@"fabs((f / tickIncrement - (int)(f / tickIncrement))) : %f",fabs((f / tickIncrement - (int)(f / tickIncrement))));

    float checkValue = (f / tickIncrement - (int)(f / tickIncrement));

    if (fabs(checkValue) < 0.05) { // if is major tick
        myTickLength = self.tickLength;
        NSString *string = [[NSString alloc] initWithFormat:@"%0.1f", f];
        float textWidth = textHeight * [string length] / 2;
        CGContextShowTextAtPoint(ctx, centerX + cos(angle) * (radius - textInset) - textWidth / 2.0, centerY + sin(angle) * (radius - textInset) + textHeight / 4.0, [string UTF8String], [string length]);
        [string release];

    } else {
        myTickLength = self.minorTickLength;
    }

    points[i++] = CGPointMake(centerX + cos(angle) * (radius - myTickLength - tickInset), centerY + sin(angle) * (radius - myTickLength - tickInset));

    angle += minorTickAngleIncrement;
}

The following output is been displayed :

 f : 0.100000
 tickIncrement : 0.100000
 f / tickIncrement : 1.000000
 (int)(f / tickIncrement) : 1
 (f / tickIncrement - (int)(f / tickIncrement)) : 0.000000
  fabs((f / tickIncrement - (int)(f / tickIncrement))) : 0.000000

  f : 0.120000
 tickIncrement : 0.100000
 f / tickIncrement : 1.200000
 (int)(f / tickIncrement) : 1
 (f / tickIncrement - (int)(f / tickIncrement)) : 0.200000
 fabs((f / tickIncrement - (int)(f / tickIncrement))) : 0.200000

 f : 0.140000
 tickIncrement : 0.100000
 f / tickIncrement : 1.400000
 (int)(f / tickIncrement) : 1
 (f / tickIncrement - (int)(f / tickIncrement)) : 0.400000
 fabs((f / tickIncrement - (int)(f / tickIncrement))) : 0.400000

 f : 0.160000
 tickIncrement : 0.100000
 f / tickIncrement : 1.600000
 (int)(f / tickIncrement) : 1
 (f / tickIncrement - (int)(f / tickIncrement)) : 0.600000
 fabs((f / tickIncrement - (int)(f / tickIncrement))) : 0.600000

 f : 0.180000
 tickIncrement : 0.100000
 f / tickIncrement : 1.800000
 (int)(f / tickIncrement) : 1
 (f / tickIncrement - (int)(f / tickIncrement)) : 0.800000
 fabs((f / tickIncrement - (int)(f / tickIncrement))) : 0.800000

 f : 0.200000
 tickIncrement : 0.100000
 f / tickIncrement : 2.000000
 **(int)(f / tickIncrement) : 1**
 (f / tickIncrement - (int)(f / tickIncrement)) : 1.000000
 fabs((f / tickIncrement - (int)(f / tickIncrement))) : 1.000000

...................

Where, you can see that in the last block of output (int)(f / tickIncrement) : 1 must return 2, but instead it returns 1.

Why does this happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:30:15+00:00Added an answer on May 30, 2026 at 2:30 pm

    Most likely, you’re running into floating point representation problems.
    Try using a double, but know that it isn’t going to solve the underlying problem, that the 2.0 you see is actually 1.99999 ... that is simply getting formatted to show 2.0

    Read “What Every Computer Scientist Should Know About Floating-Point Arithmetic“

    In the meantime, try simply using:

    (int)(f / tickIncrement + tickIncrement / 5.0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I run this Windows Server 2008 security update and this code block is
when i run this code : CONADefinitions.CONAPI_FOLDER_INFO2 FolderInfo; int iResult = 0; IntPtr Buffer
When I run this code the selected item is not visible. I've already tried
When I run this code, About half-way through the concatenation loop, $xml becomes null
I've narrowed down the issue I'm having to this block of code, where I
I'm trying to create a Rails app template I have this block of code
So I have this block of code. Basically, I'm taking file $i, checking if
How can I run code block in background periodically using GCD? I am trying
Say I have a block of code I would like to test like this:
I have this block of code executed when pressing a number: NSString *currentValue =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.