473,324 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Float question - different compilers

cru
I have a question in regard to floating point calculation behavior
that exists between different compilers on the same hardware. Say, the
difference between a console app written in windows using visaul c++
vs. linux and gcc. I seem to recall running into problems with this in
the past (floating point calculations using different compilers) but I
can't come up with a simple yet concrete example. Any small snippet of
code that exhibits different behavior in regard to floating point
calculations on different compilers would be helpful. Or am I simply
imagining things and there really are no differences?
Jul 19 '05 #1
2 1607
"cru" <cr****@yahoo.com> wrote...
I have a question in regard to floating point calculation behavior
that exists between different compilers on the same hardware. Say, the
difference between a console app written in windows using visaul c++
vs. linux and gcc. I seem to recall running into problems with this in
the past (floating point calculations using different compilers) but I
can't come up with a simple yet concrete example. Any small snippet of
code that exhibits different behavior in regard to floating point
calculations on different compilers would be helpful. Or am I simply
imagining things and there really are no differences?


Quite possible. But don't let that stop you. If _you_ find some "small
snippet of code that exhibits", let us know. In all I've seen there are
no differences.

Victor
Jul 19 '05 #2
Hi,

some compilers are converting float internally to double. The following code
will detect this:

#include <iostream>
int main()
{
float fnum = 7.7;
double dnum = 7.7;

double d1 = fnum; // !!!
double d2 = dnum; // !!!

if( d1 == d2 )
std::cout << "The values are equal." << std::endl;
else
std::cout << "The values are NOT equal." << std::endl;

return 0;
}
Ralf
www.oop-trainer.de

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pat | last post by:
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...
4
by: Jonathan Fielder | last post by:
Hi, My program (below) casts a double (which is in range for a float) to a float. As far as I know this should give me the nearest representable float, which will loose some precision. I...
9
by: Sisyphus | last post by:
Hi, I have some software that does the following (in an attempt to determine whether the double x, can be represented just as accurately by a float): void test_it(double x) { float y = x;...
1
by: Peter Knörrich | last post by:
Hello, I've found another inconsistency, and looking through the list archives I can find mentions of funky stuff like print float('inf') giving Infanity
27
by: galt_57 | last post by:
I need to do just a few multiplies of long integers and have a divide by ten. Can I avoid using floats? Can I use two longs as a 64 bit value somehow? Thanks.
116
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...
10
by: Chris Stankevitz | last post by:
Is this a fast way to invert a float: inline Invert(float& f) { f *= -1.0f; } I'd like the CPU to flip the sign bit (and not carry out a float-float multiplication). Please enlighten me! ...
6
by: vlsidesign | last post by:
Newbie question: 0 converted to 0.0 for float variable? If I have the following code, float myTotal; myTotal = 0; will C automatically add a decimal point and at least one zero to the right...
8
by: d major | last post by:
I was very puzzled about the conversion between float and long, I cann't understand why a long val can convert to a float, as the below codes show: typedef unsigned long u_long; float val =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.