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

The Archive Base Latest Questions

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

I am aware of the errors that can occur when doing conversions between floating

  • 0

I am aware of the errors that can occur when doing conversions between floating point numbers and integers, but what about performance (please disregard the accuracy issues)?

Does performance, in general, suffer if I do n-ary operations on operands of differing arithmetic types, that is, on differing floating point types (e.g. float and double) and floating point/integer type combinations (e.g. float and int)? Do there exist rules of thumb, such as, to keep all operands the same type?

P.S.: I am asking because I’m writing an expression template library and would like to know whether to allow binary operations on vectors containing values of differing arithmetic types.

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

    I suspect the answer to this question is going to vary by target architecture, because the conversions can (but might not) to occur in hardware. For example, consider the following code, which causes some interconversions between int and float:

    int main (int argc, char** argv)
    {
        int precoarced = 35;
        // precoarced gets forced to float
        float result = 0.5 + precoarced;
    
        // and now we force it back to int
        return (int)result;
    
        // I wonder what the disassembly looks like in different environments?
    }
    

    When I tried to compile this with g++ (I’m on Ubuntu, x86) with default settings, and used gdb to disassemble:

       0x00000000004004b4 <+0>: push   %rbp
       0x00000000004004b5 <+1>: mov    %rsp,%rbp
       0x00000000004004b8 <+4>: mov    %edi,-0x14(%rbp)
       0x00000000004004bb <+7>: mov    %rsi,-0x20(%rbp)
       0x00000000004004bf <+11>:    movl   $0x23,-0x8(%rbp)
       0x00000000004004c6 <+18>:    cvtsi2sdl -0x8(%rbp),%xmm0
       0x00000000004004cb <+23>:    movsd  0x10d(%rip),%xmm1        # 0x4005e0
       0x00000000004004d3 <+31>:    addsd  %xmm1,%xmm0
       0x00000000004004d7 <+35>:    unpcklpd %xmm0,%xmm0
       0x00000000004004db <+39>:    cvtpd2ps %xmm0,%xmm0
       0x00000000004004df <+43>:    movss  %xmm0,-0x4(%rbp)
       0x00000000004004e4 <+48>:    movss  -0x4(%rbp),%xmm0
       0x00000000004004e9 <+53>:    cvttss2si %xmm0,%eax
       0x00000000004004ed <+57>:    pop    %rbp
       0x00000000004004ee <+58>:    retq   
    

    Note the instructions with a cvt-prefixed mnemonic. These are conversion instructions. So in this case, the conversion is happening in hardware in a handful of instructions. So, depending on how many cycles these instructions cost, it could be reasonably fast. But again, a different architecture (or different compiler) could change the story.

    Edit: On a fun side note, there’s an extra conversion in there due to me accidentally specifying 0.5 instead of 0.5f. That’s why the cvtpd2ps op is in there.

    Edit: x86 has had FP support for a long time (since the 80s), so C++ compilers targeting x86 will generally make use of the hardware (unless the compiler is seriously behind the times). Thanks Hot Licks for pointing this out.

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

Sidebar

Related Questions

I aware that this will be a less programming question, but still... How can
Is there a description of the various errors that NSXMLParser can return? I'm aware
Yes, it's the infamous viewstate again! Now I am aware that problems can ocurr
I have a form in a Django template. I am aware that I can
I'm aware that I can use a table value parameter as another option and
Are aware of any solution that let me deactivate my facebook account through an
BE AWARE! Creating spyware, computer viruses and similar nasties can be illegal where you
Data-aware controls can be linked to datasets to display data contained in fields in
I'm aware of using custom configuration values for my custom services, but what if
I'm aware it's a quite simple question but I'm a newbie to C#, ASP.NET

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.