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 6693733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:01:12+00:00 2026-05-26T06:01:12+00:00

TLDR: How do I call standard floating point code in a way that compiles

  • 0

TLDR: How do I call standard floating point code in a way that compiles both 32 and 64 bit CGFloats without warnings?


CGFloat is defined as either double or float, depending on the compiler settings and platform. I’m trying to write code that works well in both situations, without generating a lot of warnings.

When I use functions like floor, abs, ceil, and other simple floating point operations, I get warnings about values being truncated. For example:

warning: implicit conversion shortens 64-bit value into a 32-bit value

I’m not concerned about correctness or loss of precision in of calculations, as I realize that I could just use the double precision versions of all functions all of the time (floor instead of floorf, etc); however, I would have to tolerate these errors.

Is there a way to write code cleanly that supports both 32 bit and 64 bit floats without having to either use a lot of #ifdef __ LP64 __ ‘s, or write wrapper functions for all of the standard floating point functions?

  • 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-26T06:01:13+00:00Added an answer on May 26, 2026 at 6:01 am

    You may use those functions from tgmath.h.

    #include <tgmath.h>
    
    ...
    
    double d = 1.5;
    double e = floor(d);   // will choose the 64-bit version of 'floor'
    
    float f = 1.5f;
    float g = floor(f);    // will choose the 32-bit version of 'floorf'.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

TLDR I have a function that runs on the end of a pan in
TLDR : Tell IE6/7 users to leave in a nice way :) whilst blocking
TLDR : Can the onreadystatechange event be emulated somehow else for synchronous requests without
TLDR: I'm looking for a way to serve web resources (css, jpg, etc) from
TLDR: Does anyone have experience of both protovis & D3.js to illuminate the differences
TLDR Version: I need to find a way to implement some sort of MessageCenter
TLDR ; I need simple a Python call given a package name (e.g., 'make')
TLDR: if I built a multipurpose parser by hand with different code for each
TLDR version: For caching many small database tables that rarely change in my .NET4
Update: This may be something that just isn't doable. See this TLDR: How do

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.