Give two double-typed variable X and Y.
If (X==Y) is true,
then how about the following results:
(float(X) > float(Y))?
(float(X) < float(Y))?
(float(X) >= float(Y))?
( X > float(Y) )?
( X < float(Y) )?
( X == float(Y) )?
Will the results be independent of compliers and OS platforms?
Thanks. Pat 5 1860
"Pat" <Pa*@Pat.com> wrote... Give two double-typed variable X and Y.
If (X==Y) is true,
then how about the following results: (float(X) > float(Y))? (float(X) < float(Y))? (float(X) >= float(Y))? ( X > float(Y) )? ( X < float(Y) )? ( X == float(Y) )?
Will the results be independent of compliers and OS platforms?
Unless there is an overflow (resulting in infinity values), the
expression
float(X) == float(Y)
should always evaluate 'true' if X == Y evaluates 'true'.
Also, if you attempt to compare float(X) and Y [or X and float(Y)],
both will be converted back to 'double' and the result will most
definitely depend on values of X and Y, compiler, and hardware.
Victor
Pat,
I did some experiments, I found that float(X) is rounding on my MVC++
compiler, so if X=0.499999999, float(X) = 0.5, but if X = 0.511111111,
float(X) = 0.51111, so we get both > and < situations.
If X == Y, then always float(X) == float(Y)
dave
"Pat" <Pa*@Pat.com> wrote in message news:40**********@rain.i-cable.com... Give two double-typed variable X and Y.
If (X==Y) is true,
then how about the following results: (float(X) > float(Y))? (float(X) < float(Y))? (float(X) >= float(Y))? ( X > float(Y) )? ( X < float(Y) )? ( X == float(Y) )?
Will the results be independent of compliers and OS platforms?
Thanks. Pat
Dave Townsend wrote: Pat,
I did some experiments, I found that float(X) is rounding on my MVC++ compiler, so if X=0.499999999, float(X) = 0.5, but if X = 0.511111111, float(X) = 0.51111, so we get both > and < situations.
Think about this for a moment; abs(0.5-499999999) !=
abs(0.5-0.511111111). 7 orders of magnitude difference.
Ian
If X == Y, then always float(X) == float(Y)
dave
"Pat" <Pa*@Pat.com> wrote in message news:40**********@rain.i-cable.com...
Give two double-typed variable X and Y.
If (X==Y) is true,
then how about the following results: (float(X) > float(Y))? (float(X) < float(Y))? (float(X) >= float(Y))? ( X > float(Y) )? ( X < float(Y) )? ( X == float(Y) )?
Will the results be independent of compliers and OS platforms?
Thanks. Pat
Ian,
Sorry, not following what you said.
I'm saying that because the float type casting operation rounds, in some
cases
it will round down and some it will round up, so we get both < and > for the
examples.
dave
"Ian" <no***@nowhere.com> wrote in message
news:10***************@drone5.qsi.net.nz... Dave Townsend wrote: Pat,
I did some experiments, I found that float(X) is rounding on my MVC++ compiler, so if X=0.499999999, float(X) = 0.5, but if X = 0.511111111, float(X) = 0.51111, so we get both > and < situations. Think about this for a moment; abs(0.5-499999999) != abs(0.5-0.511111111). 7 orders of magnitude difference.
Ian
If X == Y, then always float(X) == float(Y)
dave
"Pat" <Pa*@Pat.com> wrote in message
news:40**********@rain.i-cable.com...Give two double-typed variable X and Y.
If (X==Y) is true,
then how about the following results: (float(X) > float(Y))? (float(X) < float(Y))? (float(X) >= float(Y))? ( X > float(Y) )? ( X < float(Y) )? ( X == float(Y) )?
Will the results be independent of compliers and OS platforms?
Thanks. Pat
Pat wrote: Give two double-typed variable X and Y.
If (X==Y) is true,
then how about the following results: (float(X) > float(Y))? (float(X) < float(Y))? (float(X) >= float(Y))? ( X > float(Y) )? ( X < float(Y) )? ( X == float(Y) )?
Will the results be independent of compliers and OS platforms?
Thanks. Pat
No, they will not be independent of compilers, nor of OS platforms.
Floating point numbers, the underlying machine instructions and
registers that manage them are different. You will get subtle
differences, especially as you increase in precision. We have trouble on
a regular basis with floating point numbers in our software, compounded
when we port to different platforms.
Floating point numbers are good to use in some situations, but you
REALLY want to avoid comparing them whenever possible.
David Logan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christian Christmann |
last post by:
Hi,
just a general question.
Which data type is more precise for large values:
float or double?
Thank you.
Chris
|
by: Andy |
last post by:
Hi,
I don't know if this is the correct group to post this, but
when I multiply a huge floating point value by a really
small (non-zero) floating point value, I get 0 (zero) for the result.
This...
|
by: guy |
last post by:
Can someone point me to page that gives a decision tree on deciding when to
use float or double in a C# application including performance impacts of
using one over the other. And when is decimal...
|
by: Bruno van Dooren |
last post by:
Hi,
i have a simple question that has bothered me for some time now.
if i have a function foo( double a)
and i do something like
float b = 2.0;
foo(b);
|
by: abdul_n_khan |
last post by:
Hello,
I have a basic question related to datatypes.
I am trying to read a value using Microsoft's ADO recordset from a
field (lets call it 'Price') with datatype decimal(19,6) => 19 =
Precision,...
| |
by: Erick-> |
last post by:
hi all...
I've readed some lines about the difference between float and double
data types... but, in the real world, which is the best? when should we
use float or double??
thanks
Erick
|
by: hantechs |
last post by:
<html>
<body>
<p style="width:30%;">text1</p>
<p style="float:left;">text2</p>
</body>
</html>
The effect of this html code is : text1 and text2 each is on a line.
My question is: Why text2...
|
by: Dilip |
last post by:
Recently in our code, I ran into a situation where were stuffing a
float inside a double. The precision was extended automatically
because of that. To make a long story short, this caused...
|
by: Shirsoft |
last post by:
I have a 32 bit intel and 64 bit AMD machine. There is a rounding
error in the 8th digit. Unfortunately because of the algorithm we use,
the errors percolate into higher digits.
C++ code is...
|
by: Bill Reid |
last post by:
I just noticed that my "improved" version of sscanf() doesn't assign
floating point numbers properly if the variable assigned to is declared
as a "float" rather than a "double". (This never...
|
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...
| |
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...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |