473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Exponents Major ?Bug?

Greetings,

I have the expression that works in Excel, Javascript, and VB.NET:

B1 = 18

10^(3*(B1)/1130)*6

Result: 6.697903112
When I evaluate in C#,
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);

I get the wrong result.

Funny, when I add that Math.Pow part to VB.NET and JScript.NET, I get the
same incorrect result.

How can I get the correct result in C#?
Thanks,
Shawn
Nov 15 '05 #1
8 2441
Do we have to mindread to get the WRONG result value in C#?

why mix float and doubles?

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Shawn B." <le****@html.com> wrote in message
news:uG*************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have the expression that works in Excel, Javascript, and VB.NET:

B1 = 18

10^(3*(B1)/1130)*6

Result: 6.697903112
When I evaluate in C#,
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);

I get the wrong result.

Funny, when I add that Math.Pow part to VB.NET and JScript.NET, I get the
same incorrect result.

How can I get the correct result in C#?
Thanks,
Shawn

Nov 15 '05 #2
I would presume, the WRONG result to be anything other than the CORRECT
result. If B1 was instead 18, and I place it in the stead of B1 in the C#
expressions, it will still fail to result in the correct answer
"6.697903112".
Thanks,
Shawn
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:%2***************@TK2MSFTNGP10.phx.gbl...
Do we have to mindread to get the WRONG result value in C#?

why mix float and doubles?

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Shawn B." <le****@html.com> wrote in message
news:uG*************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have the expression that works in Excel, Javascript, and VB.NET:

B1 = 18

10^(3*(B1)/1130)*6

Result: 6.697903112
When I evaluate in C#,
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);

I get the wrong result.

Funny, when I add that Math.Pow part to VB.NET and JScript.NET, I get the same incorrect result.

How can I get the correct result in C#?
Thanks,
Shawn


Nov 15 '05 #3
If I cast B1,

float B1 = 18;
double x;
double y=0;

x = (3*(double)B1/1130) * 6;
x = Math.Pow(x, 10);

the incorrect answer would be: 3.75548184850977E-06
which is the same as if I don't cast it. Mind you, if I user Math.Pow(x,
10) in JScript.NET or VB.NET, I get the same incorrect answer. But if I use
the power operators (available in those languages) instead of Math.Pow() I
get the correct answer: 6.697903112
Thanks,
Shawn

"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:%2***************@TK2MSFTNGP10.phx.gbl...
Do we have to mindread to get the WRONG result value in C#?

why mix float and doubles?

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Shawn B." <le****@html.com> wrote in message
news:uG*************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have the expression that works in Excel, Javascript, and VB.NET:

B1 = 18

10^(3*(B1)/1130)*6

Result: 6.697903112
When I evaluate in C#,
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);

I get the wrong result.

Funny, when I add that Math.Pow part to VB.NET and JScript.NET, I get the same incorrect result.

How can I get the correct result in C#?
Thanks,
Shawn


Nov 15 '05 #4
Shawn B. wrote:
Greetings,

I have the expression that works in Excel, Javascript, and VB.NET:

B1 = 18

10^(3*(B1)/1130)*6

Result: 6.697903112
When I evaluate in C#,
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);

I get the wrong result.
You get a different result because the expressions are not equivalent.

The C# equivalent of your Excel, JavaScript & VB.NET expression is:

Math.Pow( 10, (3*B1/1130)) * 6

The exponent is (3*B1/1130), which should be the 2nd parameter to
Math.Pow().

Note that 6 is not passed to Math.Pow() - it's not part of the exponent
in your original expression.

Funny, when I add that Math.Pow part to VB.NET and JScript.NET, I get the
same incorrect result.

How can I get the correct result in C#?
Thanks,
Shawn


Nov 15 '05 #5
Shawn,
C# gives you a different answer, as you gave C# a different problem! :-)

Remember that Math.Pow(x, y) returns x ^ y.
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);
Asks C# to solve:

((3*(B1)/1130)*6) ^ 10

If you flip the parameters to Math.Pow, you get the answer you expect!
x = Math.Pow(10, x);
Hope this helps
Jay
"Shawn B." <le****@html.com> wrote in message
news:uG*************@TK2MSFTNGP10.phx.gbl... Greetings,

I have the expression that works in Excel, Javascript, and VB.NET:

B1 = 18

10^(3*(B1)/1130)*6

Result: 6.697903112
When I evaluate in C#,
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);

I get the wrong result.

Funny, when I add that Math.Pow part to VB.NET and JScript.NET, I get the
same incorrect result.

How can I get the correct result in C#?
Thanks,
Shawn

Nov 15 '05 #6
Mike,
Doh! I saw the flipped parameters, I missed the parenthesis.

Shawn, Mike's answer is more correct ;-)

Jay

"mikeb" <ma************@mailnull.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Shawn B. wrote:
Greetings,

I have the expression that works in Excel, Javascript, and VB.NET:

B1 = 18

10^(3*(B1)/1130)*6

Result: 6.697903112
When I evaluate in C#,
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);

I get the wrong result.


You get a different result because the expressions are not equivalent.

The C# equivalent of your Excel, JavaScript & VB.NET expression is:

Math.Pow( 10, (3*B1/1130)) * 6

The exponent is (3*B1/1130), which should be the 2nd parameter to
Math.Pow().

Note that 6 is not passed to Math.Pow() - it's not part of the exponent
in your original expression.

Funny, when I add that Math.Pow part to VB.NET and JScript.NET, I get the same incorrect result.

How can I get the correct result in C#?
Thanks,
Shawn

Nov 15 '05 #7
Thank you.
Thanks,
Shawn

"mikeb" <ma************@mailnull.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Shawn B. wrote:
Greetings,

I have the expression that works in Excel, Javascript, and VB.NET:

B1 = 18

10^(3*(B1)/1130)*6

Result: 6.697903112
When I evaluate in C#,
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);

I get the wrong result.


You get a different result because the expressions are not equivalent.

The C# equivalent of your Excel, JavaScript & VB.NET expression is:

Math.Pow( 10, (3*B1/1130)) * 6

The exponent is (3*B1/1130), which should be the 2nd parameter to
Math.Pow().

Note that 6 is not passed to Math.Pow() - it's not part of the exponent
in your original expression.

Funny, when I add that Math.Pow part to VB.NET and JScript.NET, I get the same incorrect result.

How can I get the correct result in C#?
Thanks,
Shawn

Nov 15 '05 #8
Jack:
Do you get a kick out of spoofing my name and email to be an idiot? Does
that make you feel better to pass yourself off as me? You need to grow up,
and stop using my name and email as yours please.

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Alvin Bruney" <vapordan_spam_me_not@hotmail_no_spamhotmail.com > wrote in
message news:#X*************@TK2MSFTNGP10.phx.gbl...
Do we have to mindread to get the WRONG result value in C#?

why mix float and doubles?

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Shawn B." <le****@html.com> wrote in message
news:uG*************@TK2MSFTNGP10.phx.gbl...
Greetings,

I have the expression that works in Excel, Javascript, and VB.NET:

B1 = 18

10^(3*(B1)/1130)*6

Result: 6.697903112
When I evaluate in C#,
float B1 = 18;
double x;

x = (3*B1/1130) * 6;
x = Math.Pow(x, 10);

I get the wrong result.

Funny, when I add that Math.Pow part to VB.NET and JScript.NET, I get the same incorrect result.

How can I get the correct result in C#?
Thanks,
Shawn


Nov 15 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Doe | last post by:
Does anyone understand what a 'raw device number' is with respect os.major() and os.minor() Found in os-file-dir.html, section 6.1.4, os.major() description is: major(device) Extracts a...
5
by: Bootstrap Bill | last post by:
Does anyone have a list of applications that have been ported to the .net framework? Does anyone know if future versions of Office will be ported? What about other Microsoft products? Games?
2
by: Alex Vinokur | last post by:
Does STL contain algorithms which generate (enable to generate) exponents, permutations, arrangements, and combinations for any numbers and words? -- Alex Vinokur mailto:alexvn@connect.to...
0
by: Oliver Elphick | last post by:
The attached proposal is written primarily for Debian. Its motivation is that the current package upgrade process is pretty flaky and also that the current packaging does not really provide for...
2
by: Stefan L | last post by:
Hi NG, I have the following problem: Is there a way to use exponents in C#-code without converting to a double and then use System.Math? I have to convert VB-Code to C# and in VB its easy...
6
by: Patrick McGovern | last post by:
Hi, quick question that's driving me nvts. how do i do exponential math in C#? -- Pat
2
by: Jef Driesen | last post by:
I'm working on a project where i need to exchange multidimensional data between C/C++ (row-major) and matlab (column-major). I understand the difference between those two mappings to linear memory....
4
by: enigmadude | last post by:
As many have heard, IronPython 1.0 was released. When I was looking through the listed differences between CPython and IronPython, the document mentioned that using large exponents such as 10 **...
12
by: zalery | last post by:
so i'm trying to set up this exponents loop, keep in mind this is my first year in computer science so my knowledge of script is somewhat minimal. basically this assignment (or at least part of it)...
3
by: Lax | last post by:
Isn't it "technically" meaningless to call C a "row major language," since there are no such things as multidimensional arrays in C. In C you can define arrays of arrays, and the way that the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.