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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:27:04+00:00 2026-06-05T05:27:04+00:00

Currently I’m rewriting some old C++ code to C#. When running some tests it

  • 0

Currently I’m rewriting some old C++ code to C#. When running some tests it didn’t work as it should, and I started debugging, and came across the below which I cant seem to figure out.

As I’m doing a lot of math in the class and using Math.Pow function very often, I created a shortcut method for it:

public double pow(double d, double p)
{
   return Math.Pow(d,p);
}

Then I have a code line as follows, which use this method quite some times:

double y = pow((pow(d12, 2) + pow(d13, 2) + pow(23, 2)), 2) - (2.0 * (pow(d12, 4) + pow(d13, 4) + pow(d23, 4)));

This line didn’t give the expected result, so I started splitting it up into smaller pieces as it should be calculated… for example the value before the minus sign should be equal to q5:

double q1 = pow(d12, 2);
double q2 = pow(d13, 2);
double q3 = pow(d23, 2);
double q4 = q1 + q2 + q3;
double q5 = pow(q4, 2);

After these lines q5 is 8775553070736.0

Then I tried splitting the long line into two parts, where the first should be equal to the above 5 lines, just written as one line:

double q12 = pow((pow(d12, 2) + pow(d13, 2) + pow(23, 2)), 2);

Which I would expect to evaluate to the same as q5, but it does not. q12 instead evaluates to 4479508755225.0

What’s wrong with the code?

  • 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-05T05:27:06+00:00Added an answer on June 5, 2026 at 5:27 am

    Why do you expect:

    pow(d23, 2)
    

    to be the same as

    pow(23, 2)
    

    ?

    PROTIP: IN VS, always change the default colour of numbers (black), to something else (I like red).

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

Sidebar

Related Questions

currently I'm developing an app for WP7 but came across a little problem with
Currently I'm doing some unit tests which are executed from bash. Unit tests are
Currently I am debugging the signing of an Android app. And this would be
Currently I have a web service running in a tomcat (http:// localhost:8080/myApp/getUsers ). My
Currently I have in my code tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addCompoundToLabel:)]; My code
I am currently running into a problem where an element is coming back from
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
Currently my server is running of the Tomcat 5.5.26 and JDK 1.5.15. Now I
Currently I have 2 web applications app1 and app2 running on Tomcat 6: app1
Currently, working with RC0 Denali, having some issues I am attempting to review data

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.