|
Welcome to the world of floating point numbers and imprecise trigonometric approximations. I think it must be the latter that's responsible for this one, as the sign bit shouldn't affect how a floating point number gets rounded.
That said, I ran an equivalent of this and it seems to give 0 for me.
|
|
|
|
|
I don't understand why your compiler give "0" and mine gives -4. Explain why?
|
|
|
|
|
Can you tell which compiler your using and version number? This is really a blow to me. I never thought this could happen.
Thanks
|
|
|
|
|
I'm using Win 7 64 bit and I'm using an interpreted language running on .Net 2.0 or 3.5 (the core libraries are the same):
$Environment:Version
2.0.50727.4971
|
|
|
|
|
It doesn't give you -4. -4.06575814682064E-20 is shorthand for -4.06575814682064 x 10^-20, that's -0.0000000000000000000406575814682064, which is pretty close to 0.
|
|
|
|
|
How can I get the program to show me "0" instead of -4.06575814682064E-20? Thank You.
|
|
|
|
|
Generally with floating point checking for exact equality is a bad idea. You probably want to check if the result is within a certain distance from 0 instead, the exact amount depends on the precision you need. As for the output, you can format it[^] to display the way you want it to.
|
|
|
|
|
Exactly.
This is not a C# problem. This is a floating-point "deficiency", although the usefulness of such a tiny fraction may be nil.
Here are documents from a few other languages that may help illustrate the issue to the OP. I particularly recommend the Python one, which one can understand without knowing anything at all about Python.
Python: Python manual[^]
Perl: Perl Cookbook[^]
|
|
|
|
|
Look at the number again and note that it's in scientific notation.
You didn't get -4.something. You got -0.00000000000000000004, which is pretty close to 0.
|
|
|
|
|
|
Look again, that's -4 x 10^-20. That's extremely close to 0.
|
|
|
|
|
C&P gives me 0 on VS 2010 / Windows 7 x64.
|
|
|
|
|
Hi,
I have procedure which returns huge xml data in ref cursor from Oracle procedure,
When the procedure is executed in Toad, it works fine, But when my method calls the procedure it returns an empty row in the datatable.
any help would be appreciated.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
What does your method return in case of errors (e.g. timeout) - an empty row?
And what's the expected size of that xml string - GigaBytes? Then you ought to consider a different design.
|
|
|
|
|
it doesn't throws any errors, now I have changed and tried using a DataReader and that works. The XML contains more than 2000 lines and file size is just 83KB.
Somehow the DataReader can perform the operation, but the DataAdapter is not filling the datatable. Is there some kind of size limit?
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
AB7771 wrote: Is there some kind of size limit?
There are always size limits.
You might try slightly below 64k if you are interested. If that doesn't work then try 32k, etc.
|
|
|
|
|
How can I display everything at both the console and a txt file.
|
|
|
|
|
Replace your Console.Write and Console.WriteLine calls with a calls to your own method - it can then call the appropriate Console and file system methods.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hello Everyone,
I would like to create my own barcode generator without using third party library.can i get some info on it?
|
|
|
|
|
Take a look at this article GenCode128 - A Code128 Barcode Generator[^]. This should help get you started. There are also plenty of other examples out there.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
|
Akshay_88 wrote: can i get some info on it?
Certainly. You can look at the answers you got when you posted[^] this question before.
|
|
|
|
|
CP holds 45 articles[^] with barcode in their title. I trust you read most of them?
|
|
|
|
|
Steps to creating your own.
1. Research what "barcode" means exactly. There are different standards. Initially probably best to pick one.
2. If you intend to print it then you are going to need to learn how to write code that prints an image.
3. You need to learn how to create an image in memory. This would be part of 2 but you need to create your own (rather than doing something like loading a jpeg file.)
4. Create code (like what you learned in 3) to implement what you learned in 1. So create a barcode image.
5. Print the image (4 and 2)
|
|
|
|
|
Hi all, I am trying to randomly select a character set from a list to be used in my function but I can't get it to work, below is what I have thus far.
public const string myChars1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const string myChars2 = "abcdefghijklmnopqrstuvwxyz";
public const string myChars3 = "0123456789";
private string RandomString()
{
char[] buffer = new char[24];
int i = 0;
while (i < 23)
{
int k = 0;
string S = "";
Random myRandomNum = new Random();
Random myRandomNum2 = new Random();
k= myRandNum2.Next(1,3);
S = Convert.ToChar(k);
buffer[i] = myChars+S[myRandNum.Next(myChars+S.Length)];
i++;
}
return new string(buffer);
}
I am trying to tack S to the end of myChars so that I will get myChars1, myChars2, or myChars3 randomly but it's not working. How could I achieve this? Any suggestions is greatly appreciated, thanks in advance for your help.
modified 19-Jul-12 13:32pm.
|
|
|
|