Hi Zaxo,
I noticed that this doesn't happen in C ...
bash-2.05b$ cat float.c
#include <stdio.h>
int main () {
float a = 36.8;
float b = 36.6;
if( a >= ( b + 0.2 ) ) { printf ("true\n"); }
}
bash-2.05b$ gcc -o float float.c
bash-2.05b$ ./float
true
... and does happen in Python ...
bash-2.05b$ cat float.py
#!/usr/bin/python
A = 36.8
B = 36.6
if( A >= B + 0.2 ):
print "true"
else:
print "false"
bash-2.05b$ ./float.py
false
I would of included a java example but I aint got all day to download the SDK. Maybe I'll update with one later. Can you explain why C deals with float point number while Perl and Python appear to have this problem? Is it a compiled verses and interpreted language issue?
Thanks
Plankton: 1% Evil, 99% Hot Gas. |
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|