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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:25:38+00:00 2026-06-13T01:25:38+00:00

I am contemplating a fixed-point arithmetic library, and in order to decide on how

  • 0

I am contemplating a fixed-point arithmetic library, and in order to decide on how much optimization should be done by the library itself (through expression templates) I started questioning how much will already be done by the optimizer. Take the following example for instance:

//This is a totally useless function to exemplify my point
void Compare(FixedPoint a, FixedPoint b) {
   if(a/b>10) {
      ... do stuff
   }
}

Now, in this function, a typical implementation of the FixedPoint class will cause

if( ( (a_<<N) / b_) > (10 <<N) ) {
... do stuff
}

Where N is the number of fractional bits. That expression could mathematically be transformed into:

(a_ > 10*b_)

even though this transformation will not result in the same behavior when you consider integer overflow. The users of my library will presumably care about the mathematical equivalence and would rather have the reduced version (possibly provided through expression templates).

Now, the question is: Will the optimizer dare do the optimization itself, even though the behavior is not strictly the same? Should I bother with such optimizations? Note that such optimizations aren’t trivial. In reality, you rarely have to do any bit shifts when you’re using fixed-point arithmetic if you actually do these optimizations.

  • 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-13T01:25:39+00:00Added an answer on June 13, 2026 at 1:25 am

    That will depend on whether the a_ and b_ types are signed or unsigned.

    In C and C++ signed overflow is technically undefined behavior, while unsigned overflow is done using two-complement arithmetic.

    Nevertheless, some compilers refuse to optimize the that code because many programs rely on the two-complement behavior of the signed overflow.

    Good modern compilers will have an option to enable/disable this particular assumption: that signed integers won’t overflow. What option is the default will vary with the compiler.

    With GCC, for example, see options -fstrict-overflow/-fno-strict-overflow and the related warning -Wstrict-overflow.

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

Sidebar

Related Questions

I am at the point in my design where I am contemplating dropping the
I am contemplating the creation of an OSX System Service as outlined here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/SysServices/introduction.html
I am contemplating doing interactive tutorials on a website i'm developing The point of
I'm looking for library that is much simpler than (Lucene in Memory search) and
I have been heavily contemplating adding the Embedded MYSQL Server Library into my application.
We're contemplating Visual Studio licensing and need to decide whether licenses for Architecture/Database/Test editions
Lately I've been contemplating whether I should start studying another framework since I only
I am contemplating designing a framework to allow for one C++ code base to
I'm contemplating a multi tenant application - shared database, shared schema. A tenant identifier
I'm contemplating the idea of implementing a XML translator using a compiler generator, based

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.