COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### int and float memory space

• Email
• Follow

Why bytes needed by int and float is machine dependent?

 0
Reply manglikalok (5) 3/21/2011 6:16:41 PM

See related articles to this posting

"alok" <manglikalok@gmail.com> wrote in message
news:17bf789c-4d85-4903-9710-e30e27f5de0c@34g2000pru.googlegroups.com...
> Why bytes needed by int and float is machine dependent?

Because machines vary on the sizes of integers and floating point values
(and, for that matter, the size of a 'byte') that they work most efficiently
with.  For example, some smaller CPUs can work efficiently with 16 bit
values; anything larger than that is a pain.  On the other extreme, some
CPUs work most efficiently with 32 or 64 bit values, and convincing them to
work with smaller integers would actually slow things down.

Now, C could preselect a specific size (and insist that all implementations
do whatever conversion is necessary to make that specific size work);
however, C has a bias towards efficiency, and so it lets the implementation
pick what's efficient (as long as it meets various minimums, for example, a
variable of type 'int' must be able to represent any value between -32767
and 32767).

--
poncho


 0
Reply Scott 3/21/2011 6:43:06 PM

On Mar 21, 11:43=A0pm, "Scott Fluhrer" <sfluh...@ix.netcom.com> wrote:
> "alok" <manglika...@gmail.com> wrote in message
>
> news:17bf789c-4d85-4903-9710-e30e27f5de0c@34g2000pru.googlegroups.com...
>
> > Why bytes needed by int and float is machine dependent?
>
> Because machines vary on the sizes of integers and floating point values
> (and, for that matter, the size of a 'byte') that they work most efficien=
tly
> with. =A0For example, some smaller CPUs can work efficiently with 16 bit
> values; anything larger than that is a pain. =A0On the other extreme, som=
e
> CPUs work most efficiently with 32 or 64 bit values, and convincing them =
to
> work with smaller integers would actually slow things down.
>
> Now, C could preselect a specific size (and insist that all implementatio=
ns
> do whatever conversion is necessary to make that specific size work);
> however, C has a bias towards efficiency, and so it lets the implementati=
on
> pick what's efficient (as long as it meets various minimums, for example,=
a
> variable of type 'int' must be able to represent any value between -32767
> and 32767).
>
> --
> poncho

Poncho,

So if the machine size is 32 bit the integer size will be 32 bit?

thanks for your wonderful reply.

 0
Reply alok 3/22/2011 5:58:55 PM

"alok" <manglikalok@gmail.com> wrote in message
news:10ede842-169f-4989-b319-375e89610026@a21g2000prj.googlegroups.com...
On Mar 21, 11:43 pm, "Scott Fluhrer" <sfluh...@ix.netcom.com> wrote:
> Poncho,
>
> So if the machine size is 32 bit the integer size will be 32 bit?

Perhaps, and perhaps not.  That's really the compiler writer's call.  The
intent in the design of C is that common C types be efficient, but there's
really nothing enforcing it.

--
poncho


 0
Reply Scott 3/22/2011 6:06:37 PM

"Scott Fluhrer" <sfluhrer@ix.netcom.com> writes:
> "alok" <manglikalok@gmail.com> wrote in message
> news:10ede842-169f-4989-b319-375e89610026@a21g2000prj.googlegroups.com...
> On Mar 21, 11:43 pm, "Scott Fluhrer" <sfluh...@ix.netcom.com> wrote:
>> So if the machine size is 32 bit the integer size will be 32 bit?
>
> Perhaps, and perhaps not.  That's really the compiler writer's call.  The
> intent in the design of C is that common C types be efficient, but there's
> really nothing enforcing it.

And in practice, it's very common to choose sizes based on compatibility
with other systems.  For example, if a 32-bit system is a direct
descendant of a similar 16-bit system, the implementer might well choose
to make int 16 bits so that code written for the older system will work
without change.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

 0
Reply Keith 3/22/2011 6:26:51 PM

On 3/22/2011 1:58 PM, alok wrote:
> [...]
> So if the machine size is 32 bit the integer size will be 32 bit?

What is "machine size?"  I think that if you try to formulate
a precise definition, you will see that the answer leads nowhere
useful.  Useful from a hardware designer's point of view, yes, but
not very useful to a software programmer.

Scott Fluhrer's explanation (paraphrase: "Different machines
are different") is pretty much the story.  Somebody designing a C
implementation considers the CPU's instruction set, possibly mixes
in some information about the CPU hardware and characteristics of
other system components, speculates about market forces, and makes
a choice: "We will use a 28-bit int, and That's That."  As C
programmers, we look at the resulting implementation and say "Oh,
28-bit ints, ugh, I want a different system" or "Hooray! 28-bit
ints, just what I've wanted all these years!" or something in
between.  And we "vote with our feet" on whether the implementor's
choice was a good one (for us) or not.

The point is this: The implementor has the freedom to make
that choice, a freedom he would not have if he were implementing
Java, say.  Java says "An int is 32 bits, whether that's convenient
or not" and hands the implementor the burden of dealing with the
fiat.  This is nice in one way, because the Java programmer doesn't
need to worry about the sizes and ranges of primitives the way the
C programmer does.  But at the same time, it means the programmer
has no way to say "I want an integer of modest size that the system
can handle with maximal ease," which is what a C programmer gets
by writing int'.

--
Eric Sosman
esosman@ieee-dot-org.invalid
`
 0
Reply Eric 3/23/2011 2:11:16 AM

5 Replies
308 Views

Similar Articles

12/13/2013 2:00:03 AM
page loaded in 2474 ms. (0)

 Reply:

Similar Artilces:

Problem with float to int conversion by using two int variables for representing the float number
Create a class to operate on the US currency. Call the new class Money. All the data components in this class for dollars and cents are integer variables (this is where I get confused and don't know how to actually do the job). Include member functions and constructors to initialize Money to 0 and to initialize it to fixed values. A member function should display it in appropriate format. Include member functions that permit data conversion in both directions: - from real (float) value (4.5f US) to dollars/cents ( 4 dollar, 50 cents) - from dollars/cents (4 dollar, 50 cents) to real (float...

Problem mapping PCI memory space to user space
Hi, I want to map a local address space of my PCI device to user space. The local adress space is mapped in PCI memory space and its size is 1024 bytes. I have created a devmap entry point in my driver according to the "Writing Device Drivers" document. The drivers works on a Sparc platform but when I use it on a x86 platform mmap fails. The global error returns ENXIO. The devmap_devmem_setup() function in my driver returns -1. When I change the size of the local address space to 4096 bytes equal to page size, it works. Anyway this is no solution for me, I want to be able to map loc...

float to int
I need only integer values, so how can I convert e.g 4.5 to 5 and 4.4 to 4? I'm using DrSchme. Jorn T J�rn T Kinderas wrote: > I need only integer values, so how can I convert e.g 4.5 to 5 and 4.4 to 4? > I'm using DrSchme. Use the operations round, floor, ceiling and truncate. <http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html#%_sec_6.2.5> To avoid accumulation rounding errors, the round operations round to to even, i.e. (round 4.5) = 4 . If you are rounding financial figures, you might want to use (floor x + 0.5) -- Jens Axel S�gaard Jen...

Out of Space or Memory Error
Yesterday afternoon users suddenly could not save their Office documents to the network drive. They received an error that the Disk is Full or Memory error. The server that they are saving to has 163 gig of free space and the memory is fine also. It is not a permission thing (or quota). We do not have quotas set on the folders. Other applications (SPSS, FrontPage, Dream Weaver, etc.) can save to the folders just fine. If you save the Office document to your hard drive then move it to the network drive it will save. It only occures if you have Word, Excel, etc. open and try to save to th...

float to int conversion
System.out.println(new Float(21082007.0).intValue()); // -> 21082008System.out.println(new Double(21082007.0).intValue()); // -> 21082007Why?System.out.println(new BigDecimal(21082007.0F).intValue()); // ->21082008System.out.println(new BigDecimal(21082007.0D).intValue()); // ->21082007Again, why?And what's the proper way of doing it, using always a double?Thanks in advance On Sep 25, 8:45 am, diego.mani...@gmail.com wrote:> System.out.println(new Float(21082007.0).intValue()); // -> 21082008> System.out.println(new Double(21082007.0).intValue()); // -> 21082007>...

Fourier font spacing with \int
I use the fourier font and I would like to reduce the spacing between the \int symbol and the rest as in the following example.. Is there a way to do it? \documentclass[12pt]{article} \usepackage{fourier} \begin{document} $\int f(x)dx$ \centerline{What I would like:} $\int \!\! f(x)dx$ \end{document} Martin Chicoine <martin.chicoine@gmail.com> wrote: > I use the fourier font and I would like to reduce the spacing between > the \int symbol and the rest as in the following example.. Is there a > way to do it? > > \documentclass[12pt]{article} > \usepackage{fouri...

Convert int to float #2
Hello I have this now: > def gem(a): > g = sum(a) / len(a) > return g > print gem([1,2,3,4]) > print gem([1,10,100,1000]) > print gem([1,-2,3,-4,5]) It now gives a int, but I would like to see floats. How can I integrate that into the function? Regards, -- Guido van Brakel Life is like a box of chocolates, you never know what you're gonna get -- ...

Float to int type casting?
Hi, 1 int main() 2 { 3 float a = 17.5; 4 printf("%d\n", a); 5 printf("%d\n", *(int *)&a); 6 return 0; 7 } The output is: 0 1099694080 I could not understand why the first printf prints 0 and the other ,1099694080... I think there is sth different from simple type casting.Is it an undefined behaviour? Please let me understand. Regards. Enekajmer wrote: > Hi, > > 1 int main() > 2 { > 3 float a = 17.5; > 4 printf("%d\n", a); Here you're trying to print a float value with a conversion specifier for int. The results are u...

int -> float conversion
When int is fed into opengl (say using glVertex3i) who converts to float, CPU or GPU? Assuming a decent/powerful GPU is used? Thanks. Reza. On Sep 30, 8:41 am, RezaRob <Reza...@gmail.com> wrote: > When int is fed into opengl (say using glVertex3i) who converts to > float, CPU or GPU? Assuming a decent/powerful GPU is used? > Quite often it's CPU - don't do it! -- <\___/> / O O \ \_____/ FTB. Remove my socks for email address. fungus wrote: > On Sep 30, 8:41 am, RezaRob <Reza...@gmail.com> wrote: >> When int is fed into opengl (say u...

int(float(sys.maxint)) buglet ?
Peculiar boundary cases: >>> 2.0**31-1.0 2147483647.0 >>> int(2147483647.0) 2147483647L >>> int(2147483647L ) 2147483647 >>> >>> -2.0**31 -2147483648.0 >>> int(-2147483648.0) -2147483648L >>> int(-2147483648L ) -2147483648 some kind of one-off error? I.e., just inside extremes works: >>> [int(x) for x in (-2.0**31, -2.0**31+1.0, 2.0**31-2.0, 2.0**31-1.0)] [-2147483648L, -2147483647, 2147483646, 2147483647L] But those longs at the extremes can be converted successfully, so int(int(x)) works ;-/ >>...

int vs. float in benchmark testing
Would adding .0 to each of the numbers below turn this into a floating point test? Seems too easy. def cpu_test(): import time start = time.time() x = 0 # 0.0 while x < 9999999: # 9999999.0 x = x + 1 # 1.0 print x print (time.time()-start)/60 cpu_test() Bart Nessux wrote: > > Would adding .0 to each of the numbers below turn this into a floating > point test? Seems too easy. > > def cpu_test(): > import time > start = time.time() > x = 0 # 0.0 > while x < 9999999: ...

Accessing memory space of a STRUCT from within itself
Hi all, I have a structure like this: struct ExtState { unsigned char chgTo : 4; unsigned char SubElemID : 4; unsigned char blkProt : 1; unsigned char blkCot : 1; unsigned char : 6; // This line here void setValues (int bP = 0, int state = 0, int bC = 0) { SubElemID = EXT_STATE; chgTo = state; blkProt = bP; blkCot = bC; } }; Is there any way I can access the 6 bits (unsigned char :6) indicated above from within setValues? I am not sure on ho...

How to use BIOS INT 15 for memory sizing
Hello, I'm starting to develop under VxWorks 6.1 on a Pentium BSP. I would like to modify the bootloader, replacing the sysPhysMemTop() code with something that calls BIOS INT15/E801 for memory sizing. So, the questions: 1) Are there VXworks related BIOS INT calls and register passing examples on the net? 2) is it possible to make that BIOS call from sysPhysMemTop() without switching to real mode? Are there examples showing how to do it? Thank you in advance Best Regards Still no ideas? ;-) Bye Panino ...

Why using swap space instead of real memory?
Output from top: Box is running 3 instances of oracle. last pid: 25158; load averages: 4.72, 5.64, 6.30 12:28:49 477 processes: 467 sleeping, 5 zombie, 5 on cpu CPU states: 80.0% idle, 8.5% user, 3.9% kernel, 7.6% iowait, 0.0% swap Memory: 14G real, 7447M free, 6834M swap in use, 5846M swap free Why would swap being used instead of real memory? Could that have been instructed to used swap ? How to know. Here is buffer cache, is it too large? how about Shared memory? sysdef info 292241408 maximum memory allowed in buffer cache (bufhwm) 4294967295 max shared memory segment size (SHMMAX) SunOS...

Re: VB6 pointers and memory space question
On 7 Mar 2007 00:29:28 -0800, sublimanized@gmail.com wrote: > I was hoping somebody could help me understand what is happening here. > I am not new to VB, but i am new to pointers. > > i guess what i want to do is interprocess communication or sharing a > common memory space. > > so i have one very simple app where i declare an integer and set the > value. > > say i set the value to 200 > > now i use VarPtr(intMyVariable) to get the memory address of that > variable. > > in a seperate app i have text box where i enter a memory address (as a &g...

Amount of swap space for 8GBytes of physical memory
I've intalled AIX 5.3L on a p520 with 8GBytes of memory, taking all the defaults. Everything seems to be fine. But the swap size is just 500MBytes. Does this seem low to you? cheers Neil Not an AIX person, but yes, it **sounds** very very low. someone else will be able to give you a better answer. also, it depends on what you will be running on this machine. regards, dotyet Neil Truby wrote: > I've intalled AIX 5.3L on a p520 with 8GBytes of memory, taking all the > defaults. > Everything seems to be fine. > But the swap size is just 500MBytes. > Does this seem...

how can i extend my code space to extern memory?
I want to extend my program to extern RAM in EDK, But i can't find any document about assemble program of MICROBLAZE or POWERPC, and the usage of GENERATE LINKER SCRIPT dialog in menu TOOL->GENERATE LINKER SCRIPT,please give me some advice,thanks a lot! You should try this: <http://www.xilinx.com/xlnx/xil_ans_display.jsp?iLanguageID=1&iCountryID=1&getPagePath=13810> Hope this help This is so important for me. Thank you very much!!!! ...

how to make a simple class that is either an int or a float
Hi all, I'm not yet good at thinking the right way in c++ so although I could solve this problem, I'm not sure if they way I'm thinking of is the best way to do it. I need a data type or class or something that can hold either an int, or a float, knows which one it is holding, and will allow me to do comparisons with instances of it without the code which asks for the comparison having to know which one it is. So maybe I could do it something like this (haven't compiled it so there are probably little errors but hopefully you get the gist): class Int_or_float { int i...

Is it good to use char instead of int to save memory?
Hi, Is it recommended to use char instead of int for variables that you know never will contain a value larger than 255? A small example follows: #include <stdio.h> int main(void) { //int i = 1; char i = 1; //is this better than previous line? printf("i=%d\n",i); return 0; } What are the pros and cons of using char instead of int when values will not exceed 255? Brs, Markus Le 18-03-2010, dspfun <dspfun@hotmail.com> a écrit : > Is it recommended to use char instead of int for variables that you > know never will contain a...

Why using swap space instead of real memory? #2
Output from top: Box is running 3 instances of oracle. last pid: 25158; load averages: 4.72, 5.64, 6.30 12:28:49 477 processes: 467 sleeping, 5 zombie, 5 on cpu CPU states: 80.0% idle, 8.5% user, 3.9% kernel, 7.6% iowait, 0.0% swap Memory: 14G real, 7447M free, 6834M swap in use, 5846M swap free Why would swap being used instead of real memory? Could that have been instructed to used swap ? How to know. Here is buffer cache, is it too large? how about Shared memory? sysdef info 292241408 maximum memory allowed in buffer cache (bufhwm) 4294967295 max shared memory segment size (SHMMAX) SunOS...