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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:38:20+00:00 2026-05-16T05:38:20+00:00

float mixValue = … //in range -1.0f to 1.0f for(… ; … ; …

  • 0
float mixValue = ... //in range -1.0f to 1.0f
for(... ; ... ; ...  ) //long loop
{
    float inputLevel = ... //in range -1.0f to 1.0f
    if(inputLevel < 0.0 && mixValue < 0.0)
    {
        mixValue = (mixValue + inputLevel) + (mixValue*inputLevel);
    }
    else
    {
        mixValue = (mixValue + inputLevel) - (mixValue*inputLevel);
    }
}

just a simple question, can we calculate mixValue without branching? or any other optimization suggestion, such as using SIMD?

edit:
just for more information, I ended up
using this solution, based on chosen answer:

const float sign[] = {-1, 1};
float mixValue = ... //in range -1.0f to 1.0f
for(... ; ... ; ...  ) //long loop
{
    float inputLevel = ... //in range -1.0f to 1.0f
    unsigned a = *(unsigned*)(&mixValue);
    unsigned b = *(unsigned*)(&inputLevel);

    float mulValue = mixValue * inputLevel * sign[(a & b) >> (8*sizeof(unsigned)-1)];
    float addValue = mixValue + inputLevel;
    mixValue = addValue + mulValue;
}

thank you.

  • 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-16T05:38:21+00:00Added an answer on May 16, 2026 at 5:38 am

    Inspired by Roku’s answer (which on MSVC++10 branches), this doesn’t seem to branch:

    #include <iostream>
    
    using namespace std;
    const float sign[] = {-1, 1};
    int main() {
        const int N = 10;
        float mixValue = -0.5F;
        for(int i = 0; i < N; i++) {
            volatile float inputLevel = -0.3F;
            int bothNegative = ((((unsigned char*)&inputLevel)[3] & 0x80) & (((unsigned char*)&mixValue)[3] & 0x80)) >> 7;
            mixValue = (mixValue + inputLevel) + (sign[bothNegative]*mixValue*inputLevel);
        }
    
        std::cout << mixValue << std::endl;
    }
    

    Here’s the disassembly, as analyzed by IDA Pro (compiled on MSVC++10, Release mode):

    Disassembly http://img248.imageshack.us/img248/6865/floattestbranchmine.png

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

Sidebar

Related Questions

float Calculate(const string &query) { std::cout << Query: << query << \n; unsigned int
Same question can be asked of float... or of MinValue. I am thinking of
Possible Duplicate: php calculate float The accuracy of PHP float calculate Why does PHP
float f = 0.7; if( f == 0.7 ) printf(equal); else printf(not equal); Why
CSS Float is making me crazy, can any one explain the following situation? How
If I have a float like 3.75, how can I split it into the
float b = 1.0f; int i = (int)b; int& j = (int&)b; cout <<
float seconds = audioPlayer.currentTime; if ((seconds = 11)){ [self performSelector:@selector(viewController) withObject:nil]; } else {
Trying to get integer part of float.MaxValue but it is throwing error? long l
Like: float(1.2345678901235E+19) => string(20) "12345678901234567890" Can it be done? (it's for json_decode...)

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.