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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:54:08+00:00 2026-05-28T06:54:08+00:00

Basically for things like this (not real code): for(int i = 0; i <

  • 0

Basically for things like this (not real code):

for(int i = 0; i < 1000000000; ++i)
{
     Vert v0 = mesh.polygons[i].edges[0].vert0;
     Vert v1 = mesh.polygons[i].edges[0].vert1;

     Vector3 center = (v0.pos + v1.pos) / 2;
}

v0.pos is of type Vector3<float, float, float>, but could be Vector3<double, double, double>.

Is it safe to just do?:

Vector3 center = (v0.pos + v1.pos) * 0.5;

This might seem like premature optimization but this has to be as fast as possible that will be called on billions of points (point clouds).

  • 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-28T06:54:09+00:00Added an answer on May 28, 2026 at 6:54 am

    Not a C++ expert by any means, but in C#, doing this:

    var a = new Func<float, float, double>((float f1, float f2) => (f1 + f2) * 0.5);
    var b = new Func<float, float, double>((float f1, float f2) => (f1 + f2) / 2);
    

    generates IL that in the former:

    1. Loads the arguments
    2. Adds them (producing a single)
    3. Converts the result to a double
    4. Loads the double argument (0.5)
    5. Multiplies (producing a double)
    6. Returns the result

    and the latter

    1. Loads the arguments
    2. Adds them (producing a single)
    3. Loads the constant integer (2)
    4. Divides (producing a single, because single / integer produces a single)
    5. Converts the result to a double
    6. Returns the result

    It strikes me that the former will likely have higher precision because the multiplication is performed on 2 doubles, resulting in double precision, whereas in the latter the division is performed on a single which is upcast to a double (but still only will have the precision of the single).

    This bears me out:

    Console.Out.WriteLine(((double)1) * ((double)1/3));
    Console.Out.WriteLine((1) / ((float)3));
    

    produces:

    0.333333333333333
    0.3333333
    

    So, ‘safe’, maybe, if losing precision gaining extra precision is ok.

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

Sidebar

Related Questions

Even experienced programmers write C# code like this sometimes: double x = 2.5; double
To start out with - this is not my code - there was a
Basically things are more like black and white, on one phone (Galaxy S) works
I basically want to make things easier by just looping LinkButtons instead of making
I have one line of code which seems commented. Basically the thing I want
This is a kind of a random thing I need. Basically my setup is
Basically what I want to do it this: a pdb file contains a location
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically I have some code to check a specific directory to see if an
First of all, I'm not much of a programmer if at all. This question

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.