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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:40:49+00:00 2026-05-21T12:40:49+00:00

While using exponential operator in C#, the compiler was reporting Operator ^ cannot be

  • 0

While using exponential operator in C#, the compiler was reporting “Operator ^ cannot be applied to operands of type int and double.” While the same was compiling without any errors in VB.NET.

//C# Code, error while compiling
decimal i = 1 * (1 + 1) + 75 * 1 * (1 + 1) ^ 0.5;

'VB.NET Code. Compiled without errors 
Dim i as decimal = 1 * (1 + 1) + 75 * 1 * (1 + 1) ^ 0.5 'outputs 108.066017177982 as expected

To circumvent the C# error, I updated the code to use Math.Pow() which was giving wrong output

decimal i = 1 * (1 + 1) + 75 * 1 * (1 + 1);
i = (decimal)Math.Pow((double)i, 0.5);
Console.WriteLine(i); //Outputs 12.328828005938 instead of 108.0660172

//Next i changed the datatype to double, still same results
double i = 1 * (1 + 1) + 75 * 1 * (1 + 1);
i = Math.Pow(i, 0.5);
Console.WriteLine(i); //Outputs 12.328828005938 instead of 108.0660172

While executing the same formula in Excel, gives 108.0660172 as expected.
=1 * (1 +1) + 75 * 1 * (1 + 1) ^ 0.5

Please help me resolve this.

  • 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-21T12:40:50+00:00Added an answer on May 21, 2026 at 12:40 pm

    In C# ^ is not a power operator. It’s a Xor operator. Here is the documentation about it: ^ Operator (C# Reference)

    As for the reason why it evaluates to 12.32 is that 1 * (1 + 1) + 75 * 1 * (1 + 1) equals to 152 and sqrt(152) is about 12.32.

    On the other hand in VB and Excel it is evaluated as 1 * (1 + 1) + 75 * 1 * sqrt(2) which is 108.06.
    In c# you can express it as double i = 1 * (1 + 1) + 75 * 1 * Math.Pow((1 + 1),0.5);

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

Sidebar

Related Questions

While using Struts2, I am using several annotations to do my validations inside the
While using Vim (at home and at work), I often find myself doing similar
I am experiencing a crash while using the Boost.Spirit and Boost.Thread libraries in my
I've seen this quite a few times while using Office Interop classes this.CustomXMLParts.Add(MyResources.Data, new
I would like to create a custom XmlDeclaration while using the XmlDocument/XmlDeclaration classes in
Any idea where the setting is hiding for turning gridlines off while using excel
While generating charts using RS 2008 betas, RC0 and such., I never specified any
For a while we were using a tool called CodeVeil. I'm just wondering if
I just want a quick way (and preferably not using a while loop)of createing
I've been reading things here and there for a while now about using an

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.