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

  • Home
  • SEARCH
  • 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 9143189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:57:41+00:00 2026-06-17T09:57:41+00:00

Possible Duplicate: CGFloat addition bug? I have some code where I’m doing a lot

  • 0

Possible Duplicate:
CGFloat addition bug?

I have some code where I’m doing a lot of multiplying and dividing of CGFloats in order to figure out the correct dimensions for transformations. I notice sometimes when I’m suppose to get a value of 320, I’ll get 320.00000092 instead. Can anyone explain why this is happening and how to correct it? Is it suppose to be doing this? Here is some sample code where it’s possible the problem might be happening:

- (void) setMinimumSize
{
    CGSize superViewSize = self.superview.bounds.size;
    CGSize size = self.frame.size;

    CGFloat xScale = superViewSize.width / size.width;
    CGFloat yScale = superViewSize.height / size.height;

    CGFloat minimumScale = MIN(xScale, yScale);
    self.minimumSize = CGSizeMake(size.width * minimumScale, size.height * minimumScale);
}

- (void) scaleToMinimumSize
{
    self.transform = CGAffineTransformScale(self.transform, self.minimumSize.width / self.frame.size.width, self.minimumSize.height / self.frame.size.height);
}
  • 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-06-17T09:57:42+00:00Added an answer on June 17, 2026 at 9:57 am

    Don’t compare for equality, won’t work for float (or double), rather compare
    the difference against some delta that suits your needs for accuracy

    This is always an issue with decimal and floating points numbers.

    Ask a middle school student (1/3.0)*3.0, all will say 1. Computer says 0.999999.

    You cant expect, most of the time, 0 to be 0.000000 it will never be near to that.

    EDIT:

    If float is in so much of use, you should read this one
    http://en.wikipedia.org/wiki/IEEE_754-2008

    And also What Every Computer Scientist Should Know About Floating-Point Arithmetic,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: CGFloat addition bug? I have a CGPoint (which is just a struct
Possible Duplicate: Objective C: what is a (id) sender? I have some questions about
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: Does every Core Data Relationship have to have an Inverse? I have
Possible Duplicate: I have a nested data structure / JSON, how can I access
Possible Duplicate: Why does my cout output not appear immediately? I have a very
Possible Duplicate: Is there some ninja trick to make a variable constant after its
Possible Duplicate: Can you write object oriented code in C? Hi, can someone point
Possible Duplicate: Remove close button on jQueryUI Dialog? I am getting some problem to
Possible Duplicate: RegEx match open tags except XHTML self-contained tags I have a HTML

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.