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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:10:01+00:00 2026-05-11T20:10:01+00:00

Say you’re writing a C++ application doing lots of floating point arithmetic. Say this

  • 0

Say you’re writing a C++ application doing lots of floating point arithmetic. Say this application needs to be portable accross a reasonable range of hardware and OS platforms (say 32 and 64 bits hardware, Windows and Linux both in 32 and 64 bits flavors…).

How would you make sure that your floating point arithmetic is the same on all platforms ? For instance, how to be sure that a 32 bits floating point value will really be 32 bits on all platforms ?

For integers we have stdint.h but there doesn’t seem to exist a floating point equivalent.


[EDIT]

I got very interesting answers but I’d like to add some precision to the question.

For integers, I can write:

#include <stdint>
[...]
int32_t myInt;

and be sure that whatever the (C99 compatible) platform I’m on, myInt is a 32 bits integer.

If I write:

double myDouble;
float myFloat;

am I certain that this will compile to, respectively, 64 bits and 32 bits floating point numbers on all platforms ?

  • 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-11T20:10:02+00:00Added an answer on May 11, 2026 at 8:10 pm

    Non-IEEE 754

    Generally, you cannot. There’s always a trade-off between consistency and performance, and C++ hands that to you.

    For platforms that don’t have floating point operations (like embedded and signal processing processors), you cannot use C++ “native” floating point operations, at least not portably so. While a software layer would be possible, that’s certainly not feasible for this type of devices.

    For these, you could use 16 bit or 32 bit fixed point arithmetic (but you might even discover that long is supported only rudimentary – and frequently, div is very expensive). However, this will be much slower than built-in fixed-point arithmetic, and becomes painful after the basic four operations.

    I haven’t come across devices that support floating point in a different format than IEEE 754. From my experience, your best bet is to hope for the standard, because otherwise you usually end up building algorithms and code around the capabilities of the device. When sin(x) suddenly costs 1000 times as much, you better pick an algorithm that doesn’t need it.

    IEEE 754 – Consistency

    The only non-portability I found here is when you expect bit-identical results across platforms. The biggest influence is the optimizer. Again, you can trade accuracy and speed for consistency. Most compilers have a option for that – e.g. “floating point consistency” in Visual C++. But note that this is always accuracy beyond the guarantees of the standard.

    Why results become inconsistent?
    First, FPU registers often have higher resolution than double’s (e.g. 80 bit), so as long as the code generator doesn’t store the value back, intermediate values are held with higher accuracy.

    Second, the equivalences like a*(b+c) = a*b + a*c are not exact due to the limited precision. Nonetheless the optimizer, if allowed, may make use of them.

    Also – what I learned the hard way – printing and parsing functions are not necessarily consistent across platforms, probably due to numeric inaccuracies, too.

    float

    It is a common misconception that float operations are intrinsically faster than double. working on large float arrays is faster usually through less cache misses alone.

    Be careful with float accuracy. it can be “good enough” for a long time, but I’ve often seen it fail faster than expected. Float-based FFT’s can be much faster due to SIMD support, but generate notable artefacts quite early for audio processing.

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

Sidebar

Related Questions

Say I have this method public void test(IList<AvaliableFeaturesVm> vm) { } I have this
Say I have a method that returns this. Vector[ (PkgLine, Tree) ]() I want
Say i have this old manuscript ..What am trying to do is making the
Say I have a SqlAlchemy model something like this: from sqlalchemy.ext.declarative import declarative_base from
Say I want to test this module: import osutils def check_ip6(xml): ib_output = osutils.call('iconfig
Say I have a LINQ-to-XML query that generates an anonymous type like this: var
say i have the 3 non blocking sends like this MPI_Isend (); MPI_Isend ();
Say you have this code: private Object lockObject = new Object(); private Integer myValue
Say I have an HTML form like this to collect an email from a
Say you have an application divided into 3-tiers: GUI, business logic, and data access.

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.