|
Thanks Simon,
I understand how float number is stored in binary format, but why do you think the binary format impacts the result -- other than throw exception, infinity value will be got -- compared with integer type?
regards,
George
|
|
|
|
|
George_George wrote: Any comments, Pete?
Yup. I divided 100 by 0, and you didn't. You divided a float with a value of 100 by a float with a value of 0, which aren't actually 100 and 0. It's a subtle one, but there it is. The int class doesn't have the concept of NaN or Infinity so will yield a divide by zero exception. The converse applies to the float class.
|
|
|
|
|
Great, thanks Pete!
regards,
George
|
|
|
|
|
For int, there is exception, but for float, there is no exception. Can you reproduce?
regards,
George
|
|
|
|
|
A floating point value can be infinite, so there is no exception.
An integer can not be infinite, so an integer division will cause an exception when you divide by zero.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
What reason is there to allow a floating point number to be infinite?
there is a float.MaxValue constant that I thought was the maximum value of a single prevision float. If a float has a pre defined maximum value, why allow it to also store infinity, without all of the number in between?
[EDIT]
Interestingly, if you cast infinity to an integer, you get -2147483648, which is int.MinValue;
static void Main(string[] args)
{
try
{
float a = 100;
float b = 0;
float c = a / b;
int d = (int)c;
}
catch (Exception ex)
{
Console.WriteLine("{0}", ex.ToString());
}
return;
}
[/EDIT]
Simon
modified on Thursday, April 24, 2008 6:34 AM
|
|
|
|
|
Answered my own question.
It seems this is the IEEE standard way of handling floating point numbers:
Divide by zero exception[^]
from msdn: Dividing a floating-point value by zero will result in either positive infinity, negative infinity, or Not-a-Number (NaN) according to the rules of IEEE 754 arithmetic. Floating-point operations never throw an exception.
Single structure[^]
from msdn: If the magnitude of the result of a floating-point operation is too large for the destination format, the result of the operation is PositiveInfinity or NegativeInfinity, as appropriate for the sign of the result.
Simon
|
|
|
|
|
Thanks Simon,
1.
From the links you referred, here is the information I found related to this question. So, it means only int and decimal type has DivideByZeroException? Float/Double escape this situation?
--------------------
The exception that is thrown when there is an attempt to divide an integral or decimal value by zero.
--------------------
2.
What else information do you find relates to the question I asked in the two links you referred?
regards,
George
|
|
|
|
|
But still, the result of division by zero is undefined, not infinite.
|
|
|
|
|
PIEBALDconsult wrote: the result of division by zero is undefined, not infinite
Not according to the IEEE, and they make the rules.
Simon
|
|
|
|
|
PIEBALDconsult wrote: But still, the result of division by zero is undefined, not infinite.
Nah. The result is nullity[^].
|
|
|
|
|
Dagnabit! Now I have to add a Nullity property to my Rational class.
|
|
|
|
|
Thanks Simon,
So, the conclusion is since float has infinity value, there is no exception, but since int does not have infinity value (only has max/min value), exception will occur?
regards,
George
|
|
|
|
|
Thanks Guffa,
I think your reply makes senses. Int only has max and min value, no infinite value, but float has, right?
regards,
George
|
|
|
|
|
Only Chuck Norris can divide by zero.
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
[chuckle] Chris himself making CN jokes in the programming forums.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Hi
iam in windows application using c#.
my database is "FireBird Database".
Database path is :
string dsRelativePath = "database\\absolutemedia.fdb";
string dsAbsolutePath = Path.GetFullPath(dsRelativePath);
string ConnectionString = "ServerType=1;User=SYSDBA;Password=masterkey;Database=" +dsAbsolutePath;
//Code for upload image
OpenFileDialog opn = new OpenFileDialog();
opn.Filter = "JPEG|*.jpg|GIF|*.gif";
opn.ShowDialog();
if (opn.FileName.Length > 0)
{
this.IMG = Image.FromFile(opn.FileName);
browsetext.Text = opn.FileName;
this.resizeHeight = 240;
this.resizeWidth = 320;
IMG = this.resizeImage(IMG, new Size(resizeWidth, resizeHeight));
imagebox.Image = IMG;
}
This path is working fine upto now..
but in my application, i have an option to upload images from local drives..iam browisng an image thru "OpenFileDialog".. after selecting an image .when iam going to save ,
database path i,e dsAbsolutePath is changed to image path.it's giving error in database connection...
Error---"I/O error for file CreateFile (open) "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\database\absolutemedia.fdb"
please reply where the problem is ?
how can i rectify this .
murali krishna
|
|
|
|
|
Dear all
using Visual C# how could i making function running every 2 minutes in background of specified form by itself and must be in asynchronous mode
like checking the price of currencies or doing something inside database
thanks for all
MFC programmer
|
|
|
|
|
Use a Timer.
But remember the timer elapsed events get triggered on a different thread, so you'll need to do an Invoke call if you want to work with any GUI objects.
Simon
|
|
|
|
|
thank u sir
i have done manythings like:
using the background control to operate database processes
and used timer whith specific time interval to run the background asynchronously
best regards
modified on Thursday, April 24, 2008 5:52 AM
|
|
|
|
|
I was wondering...
There's a SendKeys function to send keys...
What about a SendClick(x, y); function?
Does one exist, that I just don't know about?
(I'm trying to avoid messy DllImports )
|
|
|
|
|
Not sure if it's exactly what you want, but my guess is you wanna click a particular button. Is myButton.PerformClick(); what you're looking for?
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Oh Cool!
Was more looking for MouseClick(x, y); for automation purposes, but WOW! That's useful!!!
Just wondering why it works in normal windows forms, but not with ASP.NET Buttons :p
|
|
|
|
|
I got this script for reading session values using Javascript
code>var color='<%= Session("color").ToString() %>'
But my requirement is to store Session values using Javascript.Can any one plz tell me how to do it ?
Thanks in Advance
|
|
|
|
|
I think u cannot assign a session using javascript that's coz session is set at server side for particular client..however u can retrieve the value from session which u have done...
Also u have posted in the wrong forum javascript in C# ?????
.....
|
|
|
|