473,387 Members | 1,771 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,387 software developers and data experts.

integer type question in linux

Joe
Hi all,
I have a linux c source code that stores a float value into a type int on
many occasions. Is this possible in linux or
does compiler round the float value into integral type? The strange thing is
that calculations have to be precise in this matter of code. Unfortunately i
dont have the linux compiler to test any of the code. Microsoft and Borland
compilers warn that loss of data will occour. I know linux is full of
surprises though.

Like:
int a = 0.1;
int b = 0.1;
int c = a +b; //is c 0 or 0.2 ?

Thanks for your answers, Joe
Nov 13 '05 #1
1 1950
"Ben Pfaff" <bl*@cs.stanford.edu> wrote in message
news:87************@pfaff.stanford.edu...
| Lew Pitcher <Le*********@td.com> writes:
| > > int a = 0.1;
| >
| > If the compiler accepts this at all, then
| > a == 0
|
| On what grounds could a compiler refuse it?

None. ISO IEC 9899-1999 §6.3.1.4:1:
"When a finite value of real floating type is converted to an integer
type other than _Bool, the fractional part is discarded (i.e., the
value is truncated toward zero)..."

Thus it is acceptable, albeit not too logical though.
Nov 13 '05 #2

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

Similar topics

61
by: John Baker | last post by:
When declaring an integer, you can specify the size by using int16, int32, or int64, with plain integer being int32. Is integer the accepted default in the programming community? If so, is...
12
by: Abhishek | last post by:
now suppose I have declared an integer value inside a function as int x; now if the return type of the function is of type (void *) then can I write return((void *)x) in side the function? I...
3
by: yawnmoth | last post by:
I'm trying to figure out how big integers in PHP can be and am having some difficulty. My first idea was to try something like this: <? for ($bits=0; (1<<($bits+1)) > (1<<$bits); $bits++);...
42
by: yong | last post by:
Hi all I have an large integer in this format x1*256^5 + x2*256^4 + x3*256^3 + x4*256^2 + x5*256 + x6 now I must convert it to this format y1*900^4 + y2*900^3 + y3*900^2 + y4*900 + y5 x1-x5...
6
by: fctk | last post by:
hello, i'm trying to compile this small program: int main(void) { unsigned long int max; max = 4000000000;
7
by: Spoon | last post by:
Hello everyone, In my code, I use uint16_t (exactly 16-bit-wide unsigned integer type) and I need to print their value in base 10. ...
30
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
Let's say we had a simple function for returning the amount of days in a month: unsigned DaysInMonth(unsigned const month) { switch (month) { case 8: case 3: case 5:
30
by: DanielJohnson | last post by:
I have seen many legacy code use uint8_t or uint16_t to override the default compiler setting of an integer's length. I am using gcc on Linux and a sizeof(int) gives me 4. I want the ability to...
7
by: laredotornado | last post by:
Hi, I'm using PHP 5 with MySql 5. I have a MySQL InnoDB table with a column of type INTEGER UNSIGNED. Is there a constant in PHP to insert the maximum value possible into the column? The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.