<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
That is interesting. Using a Red Hat 6.2 box, I took this two steps
further.
<br>First I added these two lines of code just to look at pieces:
<br> printf("%d\n", (int) ((a/b)*0.3));
<br> printf("%d\n", (int) (c*0.7));
<br>Second I changed the type of a, b, and c to float, initializing their
values to 60.00, 6.00, and 10.00 respectively.
<p>In both cases the result of the original printf line remained "10 =
9", and in both cases the results of my two new lines were 2 and 6 respectively.
<p>Then, just as a point of interest, changing the original printf statement
to
<br> printf("%2.0f = %2.0f\n", (((60/6)*0.3) + (10*0.7)), ((( a/b)*0.3)
+ ( c*0.7)))
<br>did yield "10 = 10"
<p>What up with that?
<br>
<p>Chris Cox wrote:
<blockquote TYPE=CITE>Here's the original problem... for those NTLUGgers
who want a challenge.
<p>> From: John Smith (jmsith@generic.com)
<br>> Subject: Can linux be trusted?
<br>> Newsgroups: comp.lang.c, comp.os.linux.development.apps, comp.os.linux.development.system,
comp.sys.be.programmer,
<br>> comp.sys.mac.programmer.misc, comp.unix.bsd.freebsd.misc, comp.unix.bsd.misc,
gnu.gcc
<br>> Date: 2001-02-28 17:52:12 PST
<br>>
<br>>
<br>>
<br>> "
<br>> If you've got a minute, and one of those 'bleeding edge' OSes, try
compiling
<br>> with no optimizations and running this for fun:
<br>>
<br>> int main(void)
<br>> {
<br>> int a = 60, b = 6, c = 10;
<br>>
<br>> printf("%d = %d\n", (int) (((60/6)*0.3) + (10*0.7)), (int) ((( a/b)*0.3)
+
<br>> ( c*0.7)));
<br>>
<br>> exit(1);
<br>> }
<br>>
<br>> (BTW the lameness filter defies logic, that was the best I could
do with the
<br>> C snippet)
<br>>
<br>> A friend was tortured for a few hours doing an assignment until I
took a
<br>> look at the code and realized the problem boiled down to something
that can
<br>> be reduced to this snippet.
<br>>
<br>> I compiled this with default compiler settings on every platform
I could
<br>> find. This means Digital Unix 4.0, OpenVMS 7.2, Solaris 8, IRIX 6.4,
HP-UX
<br>> 10.20, FreeBSD 4-STABLE, OpenBSD 2.8 and various Linux distros, from
ancient
<br>> to cutting edge - both with gcc and any commercial compilers that
happened
<br>> to be available at each box.
<br>>
<br>> On all Linux distros, and only on Linux distros, ranging from an
ancient
<br>> Slackware setup to the latest Red Hat, I get 9=10. On everything
else, I get
<br>> 10=10. Go figure, and remember that the whole OS is compiled with
that.
<br>>
<br>> I think I'll just stick to FreeBSD as far as my intel boxes are concerned.
<br>> "
<br>> <a href="http://slashdot.org/comments.pl?sid=01/02/28/1712232&cid=93">http://slashdot.org/comments.pl?sid=01/02/28/1712232&cid=93</a>
<br>>
<br>_______________________________________________
<br><a href="http://ntlug.org/mailman/listinfo/discuss">http://ntlug.org/mailman/listinfo/discuss</a></blockquote>
<pre>--
Consider Fractals
a large, calm, black cat
who seems often to be my spiritual leader.</pre>
</html>