[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Rounded integral division in preprocessor

From: Dave Hansen
Subject: RE: [avr-gcc-list] Rounded integral division in preprocessor
Date: Fri, 5 Feb 2010 10:13:41 -0500

From: address@hidden:

> I'm trying to do rounded (opposed to truncated) integer division with
> avr-gcc with using only preprocessor magic. This proves to be difficult:
> The current code I'm using is
> #define __IDIV(x, y) (long)(((long)x + ((long)y / 2L)) / (long)y)
> #define IDIV(x, y) (__IDIV((x), (y)))
I'm not sure why you're getting the error message, but the above seems 
unnecessarily complex.  For what it's worth, the following should have 
equivalent functionality, and does not generate the error:
#define IDIV(x,y) ( ((x)+(y)/2L)/(y) )
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]