473,395 Members | 1,797 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,395 software developers and data experts.

Problem with Scientific notification

Hi all,

I am new to c#.
I am facing a problem with exponential or scientific notification.
When I use math.pow() funciton, if the numbers are big, it returns me
in exponential format.
And when I do any arthimatic operations on that, it gives me wrong
results.
For example:

?System.Math.Pow(2,60)
1.152921504606847E+18
?System.Math.Pow(2,60)-1
1.152921504606847E+18

How can I solve this problem?
And is there a way to supress exponential notation?

Thanks in advance,
Swapna.

Nov 12 '07 #1
3 2592
On Nov 12, 10:23 am, swapna.munuk...@gmail.com wrote:
I am new to c#.
I am facing a problem with exponential or scientific notification.
When I use math.pow() funciton, if the numbers are big, it returns me
in exponential format.
No, it just returns you a double. The double itself doesn't specify a
textual representation - you need to specify your format when you call
ToString if you want a particular one.
And when I do any arthimatic operations on that, it gives me wrong
results.
For example:

?System.Math.Pow(2,60)
1.152921504606847E+18
?System.Math.Pow(2,60)-1
1.152921504606847E+18
What do you believe to be the problem here? You've gone way beyond the
bounds of double's accurate representation - how did you expect the
results to be differentiated?
How can I solve this problem?
Well, you shouldn't expect double to have more accuracy than it
actually does. If you need accurate representations of numbers this
large, you should probably be using a custom maths library. There are
some 3rd party ones around.
And is there a way to supress exponential notation?
Use the appropriate format specifier.

Jon

Nov 12 '07 #2
<sw*************@gmail.comwrote in message
news:11**********************@k35g2000prh.googlegr oups.com...
Hi all,

I am new to c#.
I am facing a problem with exponential or scientific notification.
When I use math.pow() funciton, if the numbers are big, it returns me
in exponential format.
And when I do any arthimatic operations on that, it gives me wrong
results.
For example:

?System.Math.Pow(2,60)
1.152921504606847E+18
?System.Math.Pow(2,60)-1
1.152921504606847E+18

How can I solve this problem?
And is there a way to supress exponential notation?

Thanks in advance,
Swapna.
you need 60 bits to represent that number, the maths library uses double
precision floating point
to do Pow, wich although I think is about 64 bits some of those bits are
used for the exponent leaving you less than 60 bits.
I think theres an 80 bit float but im not sure if this is in c#

if you want to keep it to a 64 bit integer youl have to write your own maths
routine I think.

I have written some basic math routines myself to replace floating point
libraries in
some small embeded microcntroller wich took too long as it doesnt have a fp
math unit,
but only for things like sqrt,atan2 etc,
however there is quite a bit of code about for such things.

a simple way to do the above would be Int64 x=(Int64)1<<60;

Colin =^.^=
Nov 12 '07 #3
Thanks a lot for your suggestions.
I will try doing the way you suggested.

Regards,
Swapna

Nov 13 '07 #4

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

Similar topics

3
by: Jeremy | last post by:
Hi, I have a webpage that is taking input from a form and using it as criteria to select data out of an sql database. The page displays an html table with the results. The user can then click a...
0
by: Greg | last post by:
I am working on an application that requires working with numbers in scientific notation. I am using SqlServer as the database and I have created strongly typed data adapters and datasets. The...
9
by: Joe Attardi | last post by:
Hi all, Math is not my strongest area so forgive me if I use some of the wrong terminology. It seems that scientific notation is immune to rounding errors. For example: (4.98 * 100) + 5.51 ...
2
by: Greg | last post by:
I am working on an application that requires working with numbers in scientific notation. I am using SqlServer as the database and I have created strongly typed data adapters and datasets. The...
0
by: Nadia Amir | last post by:
I want to enable SQL cache notification on northwind tables employees. I have used the tool aspnet_regsql.exe as defined in the tutorial http://msdn2.microsoft.com/en-us/li...02y(vs.80).aspx . It...
4
by: Christophe Charron | last post by:
Hi, is there a known bug on php 5.2.4 in wamp5 (http://www.wampserver.com/ en/index.php) about having different kinds of printing for some numeric values. This script works perfectly on an...
1
by: andi111 | last post by:
Good Morning All, I am having problems turning my Matter_Creation_Form.DOC into a Matter_Creation_Form.DOT. Now, Within Word, I have created a document that contains 2 Combo Boxes which,...
6
by: Tomasz J | last post by:
Hello developers, I bind my TextBox control specyfying a format stored in my application global ApplicationContext object - it has a static string CurrencyFormat property. The problem - this...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.