473,657 Members | 2,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

distant compilation and float literals

Hi,

I have a small problem about distant compilation and float literals.
Here is my program :

#include <stdio.h>
void main() {
float f;
double d;
f = 0.5;
printf("f=%f\n" , f);
printf("0.5=%f\ n", 0.5);
printf("0.5f=%f \n", 0.5f);
printf("0.9=%f\ n", 0.9);
printf("1.9=%f\ n", 1.9);
d = 0.5;
printf("d0.5=%f \n", d);
printf("1.0/2.0=%f\n", 1.0 / 2.0);
}

I compile on HP-UX 11.11 et then execute it :
#/usr/bin/cc c.c
#a.out
f=0.500000
0.5=0.500000
0.5f=0.500000
0.9=0.900000
1.9=1.900000
d0.5=0.500000
1.0/2.0=0.500000

Every thing is ok.

Then I compile it again from a distant solaris machine.
solaris#rsh machineHP /usr/bin/cc c.c

and execute it again on HP :
#a.out
f=0.000000
0.5=0.000000
0.5f=0.000000
0.9=0.000000
1.9=1.000000
d0.5=0.000000
1.0/2.0=0.500000

It seems thant every float literals are rounded to integer.

How can I avoid this ?

Thank you for your help.
Oct 13 '06 #1
11 1691
Christian said:
Hi,

I have a small problem about distant compilation and float literals.
Here is my program :

#include <stdio.h>
void main() {
In C, main returns int. The best way to prototype main (when you don't care
about command line arguments) is:

int main(void)

The main function has never, ever been specified either by ISO or K&R as
returning anything but int. Please, get the program's entry point right;
it's the least you can do. If you get it wrong, the program's behaviour is
undefined. I'm not saying that's what caused your weird output on Solaris,
but it's not impossible.
float f;
double d;
f = 0.5;
printf("f=%f\n" , f);
printf("0.5=%f\ n", 0.5);
printf("0.5f=%f \n", 0.5f);
printf("0.9=%f\ n", 0.9);
printf("1.9=%f\ n", 1.9);
d = 0.5;
printf("d0.5=%f \n", d);
printf("1.0/2.0=%f\n", 1.0 / 2.0);
The main function returns int, so let's return an int:

return 0;
}

I compile on HP-UX 11.11 et then execute it :
<snip>
>
Every thing is ok.
Okay.
>
Then I compile it again from a distant solaris machine.
solaris#rsh machineHP /usr/bin/cc c.c

and execute it again on HP :
#a.out
f=0.000000
0.5=0.000000
0.5f=0.000000
0.9=0.000000
1.9=1.000000
d0.5=0.000000
1.0/2.0=0.500000

It seems thant every float literals are rounded to integer.
But not the calculated value. Yes, that is strange. (Note that in fact these
are doubles, not floats, by the time they hit printf. They are promoted on
the way.)
>
How can I avoid this ?
On the face of it, the code (apart from your return type error) looks okay,
so if you are reporting the facts faithfully it looks like this might be an
implementation issue on Solaris. Perhaps you are invoking it incorrectly?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 13 '06 #2
I don't know HP C-compiler but my guess is that 'rsh' may not set your
environment up in the same way as telnet or ssh, which is probably
causing a difference.

I have seen cases in unix/linux where inetd gets manually restarted by a
sysadmin without the proper environment and inetd inherits the
sysadmin's environment, which subsequent rsh logins inherit too.

Good Luck!

Christian wrote:
Hi,

I have a small problem about distant compilation and float literals.
Here is my program :

#include <stdio.h>
void main() {
float f;
double d;
f = 0.5;
printf("f=%f\n" , f);
printf("0.5=%f\ n", 0.5);
printf("0.5f=%f \n", 0.5f);
printf("0.9=%f\ n", 0.9);
printf("1.9=%f\ n", 1.9);
d = 0.5;
printf("d0.5=%f \n", d);
printf("1.0/2.0=%f\n", 1.0 / 2.0);
}

I compile on HP-UX 11.11 et then execute it :
#/usr/bin/cc c.c
#a.out
f=0.500000
0.5=0.500000
0.5f=0.500000
0.9=0.900000
1.9=1.900000
d0.5=0.500000
1.0/2.0=0.500000

Every thing is ok.

Then I compile it again from a distant solaris machine.
solaris#rsh machineHP /usr/bin/cc c.c

and execute it again on HP :
#a.out
f=0.000000
0.5=0.000000
0.5f=0.000000
0.9=0.000000
1.9=1.000000
d0.5=0.000000
1.0/2.0=0.500000

It seems thant every float literals are rounded to integer.

How can I avoid this ?

Thank you for your help.
Oct 13 '06 #3

Christian wrote:
Hi,

I have a small problem about distant compilation and float literals.
Here is my program :

#include <stdio.h>
void main() {
float f;
double d;
f = 0.5;
printf("f=%f\n" , f);
printf("0.5=%f\ n", 0.5);
printf("0.5f=%f \n", 0.5f);
printf("0.9=%f\ n", 0.9);
printf("1.9=%f\ n", 1.9);
d = 0.5;
printf("d0.5=%f \n", d);
printf("1.0/2.0=%f\n", 1.0 / 2.0);
}

I compile on HP-UX 11.11 et then execute it :
#/usr/bin/cc c.c
#a.out
f=0.500000
0.5=0.500000
0.5f=0.500000
0.9=0.900000
1.9=1.900000
d0.5=0.500000
1.0/2.0=0.500000

Every thing is ok.

Then I compile it again from a distant solaris machine.
solaris#rsh machineHP /usr/bin/cc c.c

and execute it again on HP :
#a.out
f=0.000000
0.5=0.000000
0.5f=0.000000
0.9=0.000000
1.9=1.000000
d0.5=0.000000
1.0/2.0=0.500000

It seems thant every float literals are rounded to integer.

How can I avoid this ?

Thank you for your help.
[Note that the values are not being rounded but truncated]

Odd. As pointed out elsethread, void main is a mistake,
but I can't see it causing this problem.

Three possiblities:

The compiler on the remote machine is not
producing executables that are suitable for
your local machine. Have you tried executing
on the remote machine?

The a.out you are executing is not the a.out
you think you are executing ( maybe because
the PATH is being changed behind your back).
Have you tried using full path names?

You are not in fact reporting what actually happened,
but what you think actually happened.

The problem does not appear to be C related (any more
than this post is english related).

- William Hughes

Oct 13 '06 #4
William Hughes a écrit :
Three possiblities:

The compiler on the remote machine is not
producing executables that are suitable for
your local machine. Have you tried executing
on the remote machine?
I always use the compiler on the HP machine. I only launch it from the
remote (solaris) one.
>
The a.out you are executing is not the a.out
you think you are executing ( maybe because
the PATH is being changed behind your back).
Have you tried using full path names?
yes

And I changed the function to "int main(void)".

Same pb.

Oct 13 '06 #5
Here is the solution :

solaris#rsh sir01hp "setenv LANG C ; /usr/bin/cc c.c"

Christian a écrit :
Hi,

I have a small problem about distant compilation and float literals.
Here is my program :

#include <stdio.h>
void main() {
float f;
double d;
f = 0.5;
printf("f=%f\n" , f);
printf("0.5=%f\ n", 0.5);
printf("0.5f=%f \n", 0.5f);
printf("0.9=%f\ n", 0.9);
printf("1.9=%f\ n", 1.9);
d = 0.5;
printf("d0.5=%f \n", d);
printf("1.0/2.0=%f\n", 1.0 / 2.0);
}

I compile on HP-UX 11.11 et then execute it :
#/usr/bin/cc c.c
#a.out
f=0.500000
0.5=0.500000
0.5f=0.500000
0.9=0.900000
1.9=1.900000
d0.5=0.500000
1.0/2.0=0.500000

Every thing is ok.

Then I compile it again from a distant solaris machine.
solaris#rsh machineHP /usr/bin/cc c.c

and execute it again on HP :
#a.out
f=0.000000
0.5=0.000000
0.5f=0.000000
0.9=0.000000
1.9=1.000000
d0.5=0.000000
1.0/2.0=0.500000

It seems thant every float literals are rounded to integer.

How can I avoid this ?

Thank you for your help.
Oct 23 '06 #6

[Top posting corrected]

Christian MOENNE-LOCCOZ wrote: >>
Christian a écrit : >
Hi,

I have a small problem about distant compilation and float literals.
Here is my program :

#include <stdio.h>
void main() {
float f;
double d;
f = 0.5;
printf("f=%f\n" , f);
printf("0.5=%f\ n", 0.5);
printf("0.5f=%f \n", 0.5f);
printf("0.9=%f\ n", 0.9);
printf("1.9=%f\ n", 1.9);
d = 0.5;
printf("d0.5=%f \n", d);
printf("1.0/2.0=%f\n", 1.0 / 2.0);
}

I compile on HP-UX 11.11 et then execute it :
#/usr/bin/cc c.c
#a.out
f=0.500000
0.5=0.500000
0.5f=0.500000
0.9=0.900000
1.9=1.900000
d0.5=0.500000
1.0/2.0=0.500000

Every thing is ok.

Then I compile it again from a distant solaris machine.
solaris#rsh machineHP /usr/bin/cc c.c

and execute it again on HP :
#a.out
f=0.000000
0.5=0.000000
0.5f=0.000000
0.9=0.000000
1.9=1.000000
d0.5=0.000000
1.0/2.0=0.500000

It seems thant every float literals are rounded to integer.

How can I avoid this ?

Thank you for your help.
Here is the solution :

solaris#rsh sir01hp "setenv LANG C ; /usr/bin/cc c.c"

Kudos to lxrocks who correctly noted that rsh might
not set up the environment as expected. Presumably, if
LANG is not defined or is defined to something other than C,
the cc program does not compile ANSI C but something
else. Were you able to discover what cc was in fact doing?

- William Hughes

Oct 23 '06 #7
"William Hughes" <wp*******@hotm ail.comwrites:
[Top posting corrected]

Christian MOENNE-LOCCOZ wrote: >>
>Christian a écrit : >
Hi,

I have a small problem about distant compilation and float literals.
Here is my program :

#include <stdio.h>
void main() {
float f;
double d;
f = 0.5;
printf("f=%f\n" , f);
printf("0.5=%f\ n", 0.5);
printf("0.5f=%f \n", 0.5f);
printf("0.9=%f\ n", 0.9);
printf("1.9=%f\ n", 1.9);
d = 0.5;
printf("d0.5=%f \n", d);
printf("1.0/2.0=%f\n", 1.0 / 2.0);
}

I compile on HP-UX 11.11 et then execute it :
#/usr/bin/cc c.c
#a.out
f=0.500000
0.5=0.500000
0.5f=0.500000
0.9=0.900000
1.9=1.900000
d0.5=0.500000
1.0/2.0=0.500000

Every thing is ok.

Then I compile it again from a distant solaris machine.
solaris#rsh machineHP /usr/bin/cc c.c

and execute it again on HP :
#a.out
f=0.000000
0.5=0.000000
0.5f=0.000000
0.9=0.000000
1.9=1.000000
d0.5=0.000000
1.0/2.0=0.500000

It seems thant every float literals are rounded to integer.

How can I avoid this ?

Thank you for your help.
>Here is the solution :

solaris#rsh sir01hp "setenv LANG C ; /usr/bin/cc c.c"


Kudos to lxrocks who correctly noted that rsh might
not set up the environment as expected. Presumably, if
LANG is not defined or is defined to something other than C,
the cc program does not compile ANSI C but something
else. Were you able to discover what cc was in fact doing?
Wild guess, the locale use a coma as decimal separator, the compiler has a
call to setlocale, use strtod to do the conversion and don't very the
result, assuming that the lexer did his job correctly. The lexer did is
job correctly but strtod is locale dependant and so stop at the point.

Yours,

--
Jean-Marc
Oct 23 '06 #8

Jean-Marc Bourguet wrote:
"William Hughes" <wp*******@hotm ail.comwrites:
[Top posting corrected]

Christian MOENNE-LOCCOZ wrote: >>
Christian a écrit : >

Hi,

I have a small problem about distant compilation and float literals.
Here is my program :

#include <stdio.h>
void main() {
float f;
double d;
f = 0.5;
printf("f=%f\n" , f);
printf("0.5=%f\ n", 0.5);
printf("0.5f=%f \n", 0.5f);
printf("0.9=%f\ n", 0.9);
printf("1.9=%f\ n", 1.9);
d = 0.5;
printf("d0.5=%f \n", d);
printf("1.0/2.0=%f\n", 1.0 / 2.0);
}

I compile on HP-UX 11.11 et then execute it :
#/usr/bin/cc c.c
#a.out
f=0.500000
0.5=0.500000
0.5f=0.500000
0.9=0.900000
1.9=1.900000
d0.5=0.500000
1.0/2.0=0.500000

Every thing is ok.

Then I compile it again from a distant solaris machine.
solaris#rsh machineHP /usr/bin/cc c.c

and execute it again on HP :
#a.out
f=0.000000
0.5=0.000000
0.5f=0.000000
0.9=0.000000
1.9=1.000000
d0.5=0.000000
1.0/2.0=0.500000

It seems thant every float literals are rounded to integer.

How can I avoid this ?

Thank you for your help.
Here is the solution :

solaris#rsh sir01hp "setenv LANG C ; /usr/bin/cc c.c"

Kudos to lxrocks who correctly noted that rsh might
not set up the environment as expected. Presumably, if
LANG is not defined or is defined to something other than C,
the cc program does not compile ANSI C but something
else. Were you able to discover what cc was in fact doing?

Wild guess, the locale use a coma as decimal separator, the compiler has a
call to setlocale, use strtod to do the conversion and don't very the
result, assuming that the lexer did his job correctly. The lexer did is
job correctly but strtod is locale dependant and so stop at the point.
Does setlocale take effect during compilation?

Assuming that it does,
if we set a comma as the decimal separator, shouldn't

f=0.5;

produce a syntax error (i.e. is it acceptable for the compiler to toss
"0.5" at a function and use the result, without checking that the
entire string has been used) ?

- William Hughes

Oct 23 '06 #9
"William Hughes" <wp*******@hotm ail.comwrites:
>Wild guess, the locale use a coma as decimal separator, the compiler has a
call to setlocale, use strtod to do the conversion and don't very the
s/very/verify/
>result, assuming that the lexer did his job correctly. The lexer did is
job correctly but strtod is locale dependant and so stop at the point.

Does setlocale take effect during compilation?
My guess is that the *compiler* called setlocale (for handling messages and
character set).
Assuming that it does, if we set a comma as the decimal separator,
shouldn't

f=0.5;
produce a syntax error (i.e. is it acceptable for the compiler to toss
"0.5" at a function and use the result, without checking that the entire
string has been used) ?
My guess was that the lexer correctly ignored the setting of decimal
separator in the locale and returned the string "0.5". Then sometimes
after, the compiler needed it to be evaluated and so strtod was called
without checking the result of strtod as the lexer would not have returned
something which was not a valid representation.

Assuming my guess is correct, there is a bug in the compiler. And the bug
can well have been introduced when adding localization to the compiler, in
which case the assumption that strtod call could have been valid for years.

Yours,

--
Jean-Marc
Oct 23 '06 #10

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

Similar topics

5
12611
by: Peter Scheurer | last post by:
Hi, we found some strange behavior when operating with floats and round(). The following simplified statement reproduces the problem. select 6.56 - round(convert(float, 6.56), 2) from sysusers where name = 'public'; =========== -8.88178419
4
3862
by: Travis Stewart | last post by:
Hi, I am not very familiar with C++ so the problems I am having might be simple and I just cannot see them or I am totally unaware of why something would be incorrect. Anyway, I'm using the ANN approximate nearest neighbour libraries written by David Mount and Sunil Arya. In the ANN.h file there is a comment describing how the data types used to represent the coordinates and distances between points can be modified by the user. For my...
18
2555
by: Active8 | last post by:
I put the bare essentials in a console app. http://home.earthlink.net/~mcolasono/tmp/degub.zip Opening output.fft and loading it into a vector<float> screws up, but input1.dat doesn't. It does load the vector, too. It just craps out when you return to the console, or in a Windows app, the message loop. I think it has something to do with the vector<float> going out of scope and trying to free memory, but don't know why it would do...
4
1369
by: Marc.Tajchman | last post by:
Hi everybody, Here is a simple C++ example : 1 #include <vector> 2 3 template <typename T> 4 class X { 5 T _t; 6 public :
2
1390
by: julien | last post by:
Hi, I am using Sybase 12.5 dataserver and ASP.NET I am calling a stored procedure from my asp.net page, in this stored procedure, I have 2 float fields that are returned. One is directly taken from one float column of a table, and the other one is a substraction of 2 float columns of a table. The first field is all the time ok, whereas the calculated field is almost all the time wrong, that is it returns things like : 1,332294 - 1,334709...
15
12811
by: Kay Schluehr | last post by:
I wonder why this expression works: >>> decimal.Decimal("5.5")**1024 Decimal("1.353299876254915295189966576E+758") but this one causes an error 5.5**1024 Traceback (most recent call last):
5
4191
by: Peter Hansen | last post by:
I'm investigating a puzzling problem involving an attempt to generate a constant containing an (IEEE 754) "infinity" value. (I understand that special float values are a "platform-dependent accident" etc...) The issue appears possibly to point to a bug in the Python compiler, with it producing inconsistent results. I'm using "Python 2.4.2 (#67, Sep 28 2005, 12:41:11) on win32". This code sometimes produces a float of 1.0, sometimes...
2
13441
by: tkirankumar | last post by:
Hi all, uname -a SunOS cbmrsd1a1 5.10 Generic_118833-17 sun4us sparc FJSV,GPUZC-M g++ -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/specs Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8743
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8622
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.