Commit from zer0 on branch b_zer0 (2008-05-10 17:06 CEST)
=================================
update fixed point lib to work with gcc 4.3
aversive modules/base/math/fixed_point/f16.h 1.6.4.3
aversive modules/base/math/fixed_point/f16_add.c 1.4.4.2
aversive modules/base/math/fixed_point/f16_div.c 1.3.4.2
aversive modules/base/math/fixed_point/f16_double.c 1.5.4.2
aversive modules/base/math/fixed_point/f16_int.c 1.5.4.2
aversive modules/base/math/fixed_point/f16_inv.c 1.5.4.2
aversive modules/base/math/fixed_point/f16_mul.c 1.5.4.2
aversive modules/base/math/fixed_point/f16_neg.c 1.4.4.2
aversive modules/base/math/fixed_point/f16_print.c 1.4.4.2
aversive modules/base/math/fixed_point/f16_sqrt.c 1.5.4.3
aversive modules/base/math/fixed_point/f16_sub.c 1.4.4.2
aversive modules/base/math/fixed_point/f16_to_s16.h 1.3.6.2
aversive modules/base/math/fixed_point/f32.h 1.6.4.3
aversive modules/base/math/fixed_point/f32_add.c 1.4.4.2
aversive modules/base/math/fixed_point/f32_div.c 1.3.4.2
aversive modules/base/math/fixed_point/f32_double.c 1.5.4.2
aversive modules/base/math/fixed_point/f32_int.c 1.5.4.2
aversive modules/base/math/fixed_point/f32_inv.c 1.5.4.2
aversive modules/base/math/fixed_point/f32_mul.c 1.5.4.2
aversive modules/base/math/fixed_point/f32_neg.c 1.4.4.2
aversive modules/base/math/fixed_point/f32_print.c 1.4.4.2
aversive modules/base/math/fixed_point/f32_sqrt.c 1.5.4.3
aversive modules/base/math/fixed_point/f32_sub.c 1.4.4.2
aversive modules/base/math/fixed_point/f32_to_s32.h 1.3.6.2
aversive modules/base/math/fixed_point/f64.h 1.6.4.3
aversive modules/base/math/fixed_point/f64_add.c 1.4.4.2
aversive modules/base/math/fixed_point/f64_div.c 1.3.4.2
aversive modules/base/math/fixed_point/f64_double.c 1.5.4.2
aversive modules/base/math/fixed_point/f64_int.c 1.5.4.2
aversive modules/base/math/fixed_point/f64_inv.c 1.5.4.2
aversive modules/base/math/fixed_point/f64_msb_mul.c 1.5.4.2
aversive modules/base/math/fixed_point/f64_mul.c 1.5.4.2
aversive modules/base/math/fixed_point/f64_neg.c 1.4.4.2
aversive modules/base/math/fixed_point/f64_print.c 1.4.4.2
aversive modules/base/math/fixed_point/f64_sqrt.c 1.5.4.3
aversive modules/base/math/fixed_point/f64_sub.c 1.4.4.2
aversive modules/base/math/fixed_point/f64_to_s64.h 1.3.6.3
aversive modules/base/math/fixed_point/s16_to_f16.h 1.3.6.2
aversive modules/base/math/fixed_point/s32_to_f32.h 1.3.6.2
aversive modules/base/math/fixed_point/s64_to_f64.h 1.3.6.3
============================================
aversive/modules/base/math/fixed_point/f16.h (1.6.4.2 -> 1.6.4.3)
============================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16.h,v 1.6.4.2 2007-05-23 17:18:10 zer0 Exp $
+ * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -41,23 +41,28 @@
#include <aversive.h>
typedef struct fixed_16 {
- uint8_t decimal;
- int8_t integer;
+ union {
+ struct {
+ uint8_t decimal;
+ int8_t integer;
+ } s;
+ int16_t s16;
+ } u;
} f16;
+#define f16_decimal u.s.decimal
+#define f16_integer u.s.integer
#define F16_ZERO ( \
{ \
f16 __f; \
- __f.integer = 0; \
- __f.decimal = 0; \
+ __f.u.s16 = 0; \
__f; \
})
#define F16_NAN ( \
{ \
f16 __f; \
- __f.integer = 0xFF; \
- __f.decimal = 0xFF; \
+ __f.u.s16 = 0xFFFF; \
__f; \
})
@@ -67,8 +72,8 @@
#define F16_IS_LE(x,y) (f16_to_s16(x) <= f16_to_s16(y))
#define F16_IS_EQ(x,y) (f16_to_s16(x) == f16_to_s16(y))
#define F16_IS_NE(x,y) (f16_to_s16(x) != f16_to_s16(y))
-#define F16_IS_NEG(x) ((x).integer < 0)
-#define F16_IS_ZERO(x) ((x).integer == 0 && (x).decimal == 0)
+#define F16_IS_NEG(x) ((x).f16_integer < 0)
+#define F16_IS_ZERO(x) ((x).f16_integer == 0 && (x).f16_decimal == 0)
/** convert a double to a f16 */
================================================
aversive/modules/base/math/fixed_point/f16_add.c (1.4.4.1 -> 1.4.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_add.c,v 1.4.4.1 2006-11-26 21:06:00 zer0 Exp $
+ * Revision : $Id: f16_add.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -27,6 +27,6 @@
f16 f16_add(f16 a, f16 b)
{
- return s16_to_f16( f16_to_s16(a) + f16_to_s16(b) );
+ return s16_to_f16( f16_to_s16(a) + f16_to_s16(b) );
}
================================================
aversive/modules/base/math/fixed_point/f16_div.c (1.3.4.1 -> 1.3.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_div.c,v 1.3.4.1 2006-11-26 21:06:00 zer0 Exp $
+ * Revision : $Id: f16_div.c,v 1.3.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -25,8 +25,8 @@
f16 f16_div(f16 a, f16 b)
{
- if (F16_IS_ZERO(b))
- return F16_NAN;
- return f16_mul(a,f16_inv(b));
+ if (F16_IS_ZERO(b))
+ return F16_NAN;
+ return f16_mul(a,f16_inv(b));
}
===================================================
aversive/modules/base/math/fixed_point/f16_double.c (1.5.4.1 -> 1.5.4.2)
===================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_double.c,v 1.5.4.1 2006-11-26 21:06:00 zer0 Exp $
+ * Revision : $Id: f16_double.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -30,20 +30,19 @@
f16 f16_from_double(double d)
{
- f16 f;
- f.decimal = (uint8_t) ((d - (int8_t)d) * POW2_8F);
- f.integer = (d < 0 && f.decimal != 0 ? (int8_t)d-1 : (int8_t)d) ;
-
- return f;
+ f16 f;
+ f.f16_decimal = (uint8_t) ((d - (int8_t)d) * POW2_8F);
+ f.f16_integer = (d < 0 && f.f16_decimal != 0 ? (int8_t)d-1 : (int8_t)d)
;
+
+ return f;
}
double f16_to_double(f16 f)
{
- double d;
-
- d = f.integer;
- d += ((double)f.decimal / POW2_8F);
-
- return d;
+ double d;
+
+ d = f.f16_integer;
+ d += ((double)f.f16_decimal / POW2_8F);
+
+ return d;
}
-
================================================
aversive/modules/base/math/fixed_point/f16_int.c (1.5.4.1 -> 1.5.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_int.c,v 1.5.4.1 2006-11-26 21:06:00 zer0 Exp $
+ * Revision : $Id: f16_int.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -27,22 +27,22 @@
f16 f16_from_integer(int8_t i, uint8_t d)
{
- f16 f;
- f.integer = i;
- f.decimal = d;
+ f16 f;
+ f.f16_integer = i;
+ f.f16_decimal = d;
- return f;
+ return f;
}
/**************** int8_t <-> f16 */
f16 f16_from_msb(int8_t i)
{
- f16 f;
- f.integer = i;
- f.decimal = 0;
+ f16 f;
+ f.f16_integer = i;
+ f.f16_decimal = 0;
- return f;
+ return f;
}
@@ -50,14 +50,14 @@
f16 f16_from_lsb(int8_t i)
{
- f16 f;
+ f16 f;
if ( i >= 0 ) {
- f.integer = 0;
- f.decimal = i;
+ f.f16_integer = 0;
+ f.f16_decimal = i;
}
- else {
- f.integer = -1;
- f.decimal = i;
+ else {
+ f.f16_integer = -1;
+ f.f16_decimal = i;
}
- return f;
+ return f;
}
================================================
aversive/modules/base/math/fixed_point/f16_inv.c (1.5.4.1 -> 1.5.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_inv.c,v 1.5.4.1 2006-11-26 21:06:00 zer0 Exp $
+ * Revision : $Id: f16_inv.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -27,9 +27,9 @@
f16 f16_inv(f16 f)
{
- if (F16_IS_ZERO(f))
- return F16_NAN;
+ if (F16_IS_ZERO(f))
+ return F16_NAN;
- return s16_to_f16( ((int16_t)0x7fff) / (f16_to_s16(f)/2) );
+ return s16_to_f16( ((int16_t)0x7fff) / (f16_to_s16(f)/2) );
}
================================================
aversive/modules/base/math/fixed_point/f16_mul.c (1.5.4.1 -> 1.5.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_mul.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f16_mul.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,10 +26,8 @@
f16 f16_mul(f16 a, f16 b)
{
- return s16_to_f16( ( ((int16_t)(a.integer) * (int16_t)(b.integer)) << 8
) +
- (int16_t)(a.integer) * (int16_t)(b.decimal)
+
- (int16_t)(a.decimal) * (int16_t)(b.integer)
+
- ( ((int16_t)(a.decimal) * (int16_t)(b.decimal)) >> 8
) );
+ return s16_to_f16( ( ((int16_t)(a.f16_integer) *
(int16_t)(b.f16_integer)) << 8 ) +
+ (int16_t)(a.f16_integer) * (int16_t)(b.f16_decimal)
+
+ (int16_t)(a.f16_decimal) * (int16_t)(b.f16_integer)
+
+ ( ((int16_t)(a.f16_decimal) *
(int16_t)(b.f16_decimal)) >> 8 ) );
}
-
-
================================================
aversive/modules/base/math/fixed_point/f16_neg.c (1.4.4.1 -> 1.4.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_neg.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f16_neg.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,5 +26,5 @@
f16 f16_neg(f16 f)
{
- return s16_to_f16( -f16_to_s16(f) );
+ return s16_to_f16( -f16_to_s16(f) );
}
==================================================
aversive/modules/base/math/fixed_point/f16_print.c (1.4.4.1 -> 1.4.4.2)
==================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_print.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f16_print.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -25,9 +25,9 @@
void f16_print(f16 f)
{
- if(F16_IS_EQ(f, F16_NAN))
- printf("nan");
- else
- printf("%f",f16_to_double(f));
+ if(F16_IS_EQ(f, F16_NAN))
+ printf("nan");
+ else
+ printf("%f",f16_to_double(f));
}
=================================================
aversive/modules/base/math/fixed_point/f16_sqrt.c (1.5.4.2 -> 1.5.4.3)
=================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_sqrt.c,v 1.5.4.2 2007-06-12 16:18:43 zer0 Exp $
+ * Revision : $Id: f16_sqrt.c,v 1.5.4.3 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -43,22 +43,21 @@
f16 f16_sqrt(f16 f)
{
- uint16_t a,b,c,d;
+ uint16_t a,b,c,d;
- if (F16_IS_NEG(f))
- return F16_NAN;
+ if (F16_IS_NEG(f))
+ return F16_NAN;
- if(f.integer) {
- /* sqrt(a+b) = sqrt(a)*sqrt(1+b/a) */
- a=(uint16_t)(f.integer) << 8 ;
- b=(uint16_t)(f.decimal) << 8 ;
- c=u16_sqrt(a);
- d=u16_sqrt(0x100 + (b/a));
- return f16_mul(s16_to_f16( c<<4 ), s16_to_f16( d<<4 ));
- }
- else {
- b=(uint16_t)(f.decimal) << 8 ;
- return s16_to_f16(u16_sqrt(b));
- }
+ if(f.f16_integer) {
+ /* sqrt(a+b) = sqrt(a)*sqrt(1+b/a) */
+ a=(uint16_t)(f.f16_integer) << 8 ;
+ b=(uint16_t)(f.f16_decimal) << 8 ;
+ c=u16_sqrt(a);
+ d=u16_sqrt(0x100 + (b/a));
+ return f16_mul(s16_to_f16( c<<4 ), s16_to_f16( d<<4 ));
+ }
+ else {
+ b=(uint16_t)(f.f16_decimal) << 8 ;
+ return s16_to_f16(u16_sqrt(b));
+ }
}
-
================================================
aversive/modules/base/math/fixed_point/f16_sub.c (1.4.4.1 -> 1.4.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_sub.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f16_sub.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -27,6 +27,6 @@
f16 f16_sub(f16 a, f16 b)
{
- return s16_to_f16( f16_to_s16(a) - f16_to_s16(b) );
+ return s16_to_f16( f16_to_s16(a) - f16_to_s16(b) );
}
===================================================
aversive/modules/base/math/fixed_point/f16_to_s16.h (1.3.6.1 -> 1.3.6.2)
===================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f16_to_s16.h,v 1.3.6.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f16_to_s16.h,v 1.3.6.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -24,16 +24,16 @@
#ifdef HOST_VERSION
/* not optimized, but will work with any endianness */
-static int16_t f16_to_s16(f16 f)
+static inline int16_t f16_to_s16(f16 f)
{
- return ( ((int16_t)(f.integer))<<8 ) | ((int16_t)(f.decimal));
+ return ( ((int16_t)(f.f16_integer))<<8 ) | ((int16_t)(f.f16_decimal));
}
#else
/* only for AVR, faster */
-static int16_t f16_to_s16(f16 f)
+static inline int16_t f16_to_s16(f16 f)
{
- return ( *(int16_t *)(void *)&f);
+ return f.u.s16;
}
#endif
============================================
aversive/modules/base/math/fixed_point/f32.h (1.6.4.2 -> 1.6.4.3)
============================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32.h,v 1.6.4.2 2007-05-23 17:18:11 zer0 Exp $
+ * Revision : $Id: f32.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -41,23 +41,28 @@
#include <aversive.h>
typedef struct fixed_32 {
- uint16_t decimal;
- int16_t integer;
+ union {
+ struct {
+ uint16_t decimal;
+ int16_t integer;
+ } s;
+ int32_t s32;
+ } u;
} f32;
+#define f32_decimal u.s.decimal
+#define f32_integer u.s.integer
#define F32_ZERO ( \
{ \
f32 __f; \
- __f.integer = 0; \
- __f.decimal = 0; \
+ __f.u.s32 = 0; \
__f; \
})
#define F32_NAN ( \
{ \
f32 __f; \
- __f.integer = 0xFFFF; \
- __f.decimal = 0xFFFF; \
+ __f.u.s32 = 0xFFFFFFFF; \
__f; \
})
@@ -67,8 +72,8 @@
#define F32_IS_LE(x,y) (f32_to_s32(x) <= f32_to_s32(y))
#define F32_IS_EQ(x,y) (f32_to_s32(x) == f32_to_s32(y))
#define F32_IS_NE(x,y) (f32_to_s32(x) != f32_to_s32(y))
-#define F32_IS_NEG(x) ((x).integer < 0)
-#define F32_IS_ZERO(x) ((x).integer == 0 && (x).decimal == 0)
+#define F32_IS_NEG(x) ((x).f32_integer < 0)
+#define F32_IS_ZERO(x) ((x).f32_integer == 0 && (x).f32_decimal == 0)
/** convert a double to a f32 */
f32 f32_from_double(double f);
================================================
aversive/modules/base/math/fixed_point/f32_add.c (1.4.4.1 -> 1.4.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_add.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_add.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,6 +26,6 @@
f32 f32_add(f32 a, f32 b)
{
- return s32_to_f32( f32_to_s32(a) + f32_to_s32(b) );
+ return s32_to_f32( f32_to_s32(a) + f32_to_s32(b) );
}
================================================
aversive/modules/base/math/fixed_point/f32_div.c (1.3.4.1 -> 1.3.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_div.c,v 1.3.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_div.c,v 1.3.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -24,8 +24,7 @@
f32 f32_div(f32 a, f32 b)
{
- if (F32_IS_ZERO(b))
- return F32_NAN;
- return f32_mul(a,f32_inv(b));
+ if (F32_IS_ZERO(b))
+ return F32_NAN;
+ return f32_mul(a,f32_inv(b));
}
-
===================================================
aversive/modules/base/math/fixed_point/f32_double.c (1.5.4.1 -> 1.5.4.2)
===================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_double.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_double.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -30,20 +30,19 @@
f32 f32_from_double(double d)
{
- f32 f;
- f.decimal = (uint16_t) ((d - (int16_t)d) * POW2_16F);
- f.integer = (d < 0 && f.decimal != 0 ? (int16_t)d-1 : (int16_t)d) ;
-
- return f;
+ f32 f;
+ f.f32_decimal = (uint16_t) ((d - (int16_t)d) * POW2_16F);
+ f.f32_integer = (d < 0 && f.f32_decimal != 0 ? (int16_t)d-1 :
(int16_t)d) ;
+
+ return f;
}
double f32_to_double(f32 f)
{
- double d;
-
- d = f.integer;
- d += ((double)f.decimal / POW2_16F);
-
- return d;
+ double d;
+
+ d = f.f32_integer;
+ d += ((double)f.f32_decimal / POW2_16F);
+
+ return d;
}
-
================================================
aversive/modules/base/math/fixed_point/f32_int.c (1.5.4.1 -> 1.5.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_int.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_int.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -27,22 +27,22 @@
f32 f32_from_integer(int16_t i, uint16_t d)
{
- f32 f;
- f.integer = i;
- f.decimal = d;
+ f32 f;
+ f.f32_integer = i;
+ f.f32_decimal = d;
- return f;
+ return f;
}
/**************** int16_t <-> f32 */
f32 f32_from_msb(int16_t i)
{
- f32 f;
- f.integer = i;
- f.decimal = 0;
+ f32 f;
+ f.f32_integer = i;
+ f.f32_decimal = 0;
- return f;
+ return f;
}
@@ -50,14 +50,14 @@
f32 f32_from_lsb(int16_t i)
{
- f32 f;
+ f32 f;
if ( i >= 0 ) {
- f.integer = 0;
- f.decimal = i;
+ f.f32_integer = 0;
+ f.f32_decimal = i;
}
- else {
- f.integer = -1;
- f.decimal = i;
+ else {
+ f.f32_integer = -1;
+ f.f32_decimal = i;
}
- return f;
+ return f;
}
================================================
aversive/modules/base/math/fixed_point/f32_inv.c (1.5.4.1 -> 1.5.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_inv.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_inv.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -27,8 +27,8 @@
f32 f32_inv(f32 f)
{
- if (F32_IS_ZERO(f))
- return F32_NAN;
+ if (F32_IS_ZERO(f))
+ return F32_NAN;
- return s32_to_f32( ((int32_t)0x7fffffff) / (f32_to_s32(f)/2) );
+ return s32_to_f32( ((int32_t)0x7fffffff) / (f32_to_s32(f)/2) );
}
================================================
aversive/modules/base/math/fixed_point/f32_mul.c (1.5.4.1 -> 1.5.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_mul.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_mul.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,9 +26,8 @@
f32 f32_mul(f32 a, f32 b)
{
- return s32_to_f32( ( ((int32_t)(a.integer) * (int32_t)(b.integer)) << 16
) +
- (int32_t)(a.integer) * (int32_t)(b.decimal)
+
- (int32_t)(a.decimal) * (int32_t)(b.integer)
+
- ( ((int32_t)(a.decimal) * (int32_t)(b.decimal)) >> 16
) );
+ return s32_to_f32( ( ((int32_t)(a.f32_integer) *
(int32_t)(b.f32_integer)) << 16 ) +
+ (int32_t)(a.f32_integer) *
(int32_t)(b.f32_decimal) +
+ (int32_t)(a.f32_decimal) *
(int32_t)(b.f32_integer) +
+ ( ((int32_t)(a.f32_decimal) *
(int32_t)(b.f32_decimal)) >> 16 ) );
}
-
================================================
aversive/modules/base/math/fixed_point/f32_neg.c (1.4.4.1 -> 1.4.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_neg.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_neg.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,5 +26,5 @@
f32 f32_neg(f32 f)
{
- return s32_to_f32( -f32_to_s32(f) );
+ return s32_to_f32( -f32_to_s32(f) );
}
==================================================
aversive/modules/base/math/fixed_point/f32_print.c (1.4.4.1 -> 1.4.4.2)
==================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_print.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_print.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,9 +26,8 @@
void f32_print(f32 f)
{
- if(F32_IS_EQ(f, F32_NAN))
- printf("nan");
- else
- printf("%f",f32_to_double(f));
+ if(F32_IS_EQ(f, F32_NAN))
+ printf("nan");
+ else
+ printf("%f",f32_to_double(f));
}
-
=================================================
aversive/modules/base/math/fixed_point/f32_sqrt.c (1.5.4.2 -> 1.5.4.3)
=================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_sqrt.c,v 1.5.4.2 2007-06-12 16:18:43 zer0 Exp $
+ * Revision : $Id: f32_sqrt.c,v 1.5.4.3 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -41,25 +41,25 @@
f32 f32_sqrt(f32 f)
{
- uint32_t a,b,c,d;
+ uint32_t a,b,c,d;
- if (F32_IS_ZERO(f))
- return F32_ZERO;
+ if (F32_IS_ZERO(f))
+ return F32_ZERO;
- if (F32_IS_NEG(f))
- return F32_NAN;
+ if (F32_IS_NEG(f))
+ return F32_NAN;
- if(f.integer) {
- /* sqrt(a+b) = sqrt(a)*sqrt(1+b/a) */
- a=(uint32_t)(f.integer) << 16 ;
- b=(uint32_t)(f.decimal) << 16 ;
- c=u32_sqrt(a);
- d=u32_sqrt(0x10000 + (b/a));
- return f32_mul(s32_to_f32( c<<8 ), s32_to_f32( d<<8 ));
- }
- else {
- b=(uint32_t)(f.decimal) << 16 ;
- return s32_to_f32(u32_sqrt(b));
- }
+ if(f.f32_integer) {
+ /* sqrt(a+b) = sqrt(a)*sqrt(1+b/a) */
+ a=(uint32_t)(f.f32_integer) << 16 ;
+ b=(uint32_t)(f.f32_decimal) << 16 ;
+ c=u32_sqrt(a);
+ d=u32_sqrt(0x10000 + (b/a));
+ return f32_mul(s32_to_f32( c<<8 ), s32_to_f32( d<<8 ));
+ }
+ else {
+ b=(uint32_t)(f.f32_decimal) << 16 ;
+ return s32_to_f32(u32_sqrt(b));
+ }
}
================================================
aversive/modules/base/math/fixed_point/f32_sub.c (1.4.4.1 -> 1.4.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_sub.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_sub.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,5 +26,5 @@
f32 f32_sub(f32 a, f32 b)
{
- return s32_to_f32( f32_to_s32(a) - f32_to_s32(b) );
+ return s32_to_f32( f32_to_s32(a) - f32_to_s32(b) );
}
===================================================
aversive/modules/base/math/fixed_point/f32_to_s32.h (1.3.6.1 -> 1.3.6.2)
===================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f32_to_s32.h,v 1.3.6.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f32_to_s32.h,v 1.3.6.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -24,16 +24,16 @@
#ifdef HOST_VERSION
/* not optimized, but will work with any endianness */
-static int32_t f32_to_s32(f32 f)
+static inline int32_t f32_to_s32(f32 f)
{
- return ( ((int32_t)(f.integer))<<16 ) | ((int32_t)(f.decimal));
+ return ( ((int32_t)(f.f32_integer))<<16 ) | ((int32_t)(f.f32_decimal));
}
#else
/* only for AVR, faster */
-static int32_t f32_to_s32(f32 f)
+static inline int32_t f32_to_s32(f32 f)
{
- return ( *(int32_t *)(void *)&f);
+ return f.u.s32;
}
#endif
============================================
aversive/modules/base/math/fixed_point/f64.h (1.6.4.2 -> 1.6.4.3)
============================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64.h,v 1.6.4.2 2007-05-23 17:18:11 zer0 Exp $
+ * Revision : $Id: f64.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -41,24 +41,29 @@
#define _F64_H_
typedef struct fixed_64 {
- uint32_t decimal;
- int32_t integer;
+ union {
+ struct {
+ uint32_t decimal;
+ int32_t integer;
+ } s;
+ int64_t s64;
+ } u;
} f64;
+#define f64_integer u.s.integer
+#define f64_decimal u.s.decimal
#define F64_ZERO ( \
{ \
f64 __f; \
- __f.integer = 0; \
- __f.decimal = 0; \
+ __f.u.s64 = 0; \
__f; \
})
-#define F64_NAN ( \
-{ \
- f64 __f; \
- __f.integer = 0xFFFFFFFF; \
- __f.decimal = 0xFFFFFFFF; \
- __f; \
+#define F64_NAN ( \
+{ \
+ f64 __f; \
+ __f.u.s64 = 0xFFFFFFFFFFFFFFFF; \
+ __f; \
})
#define F64_IS_GT(x,y) (f64_to_s64(x) > f64_to_s64(y))
@@ -67,8 +72,8 @@
#define F64_IS_LE(x,y) (f64_to_s64(x) <= f64_to_s64(y))
#define F64_IS_EQ(x,y) (f64_to_s64(x) == f64_to_s64(y))
#define F64_IS_NE(x,y) (f64_to_s64(x) != f64_to_s64(y))
-#define F64_IS_NEG(x) ((x).integer < 0)
-#define F64_IS_ZERO(x) ((x).integer == 0 && (x).decimal == 0)
+#define F64_IS_NEG(x) ((x).f64_integer < 0)
+#define F64_IS_ZERO(x) ((x).f64_integer == 0 && (x).f64_decimal == 0)
/** convert a double to a f64 */
================================================
aversive/modules/base/math/fixed_point/f64_add.c (1.4.4.1 -> 1.4.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_add.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_add.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,7 +26,5 @@
f64 f64_add(f64 a, f64 b)
{
- return s64_to_f64( f64_to_s64(a) + f64_to_s64(b) );
+ return s64_to_f64( f64_to_s64(a) + f64_to_s64(b) );
}
-
-
================================================
aversive/modules/base/math/fixed_point/f64_div.c (1.3.4.1 -> 1.3.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_div.c,v 1.3.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_div.c,v 1.3.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -24,8 +24,7 @@
f64 f64_div(f64 a, f64 b)
{
- if (F64_IS_ZERO(b))
- return F64_NAN;
- return f64_mul(a,f64_inv(b));
+ if (F64_IS_ZERO(b))
+ return F64_NAN;
+ return f64_mul(a,f64_inv(b));
}
-
===================================================
aversive/modules/base/math/fixed_point/f64_double.c (1.5.4.1 -> 1.5.4.2)
===================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_double.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_double.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -30,20 +30,19 @@
f64 f64_from_double(double d)
{
- f64 f;
- f.decimal = (uint32_t) ((d - (int32_t)d) * POW2_32F);
- f.integer = (d < 0 && f.decimal != 0 ? (int32_t)d-1 : (int32_t)d) ;
+ f64 f;
+ f.f64_decimal = (uint32_t) ((d - (int32_t)d) * POW2_32F);
+ f.f64_integer = (d < 0 && f.f64_decimal != 0 ? (int32_t)d-1 :
(int32_t)d) ;
- return f;
+ return f;
}
double f64_to_double(f64 f)
{
- double d;
+ double d;
- d = f.integer;
- d += ((double)f.decimal / POW2_32F);
+ d = f.f64_integer;
+ d += ((double)f.f64_decimal / POW2_32F);
- return d;
+ return d;
}
-
================================================
aversive/modules/base/math/fixed_point/f64_int.c (1.5.4.1 -> 1.5.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_int.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_int.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,22 +26,22 @@
f64 f64_from_integer(int32_t i, uint32_t d)
{
- f64 f;
- f.integer = i;
- f.decimal = d;
+ f64 f;
+ f.f64_integer = i;
+ f.f64_decimal = d;
- return f;
+ return f;
}
/**************** int32_t <-> f64 */
f64 f64_from_msb(int32_t i)
{
- f64 f;
- f.integer = i;
- f.decimal = 0;
+ f64 f;
+ f.f64_integer = i;
+ f.f64_decimal = 0;
- return f;
+ return f;
}
@@ -49,16 +49,14 @@
f64 f64_from_lsb(int32_t i)
{
- f64 f;
+ f64 f;
if ( i >= 0 ) {
- f.integer = 0;
- f.decimal = i;
+ f.f64_integer = 0;
+ f.f64_decimal = i;
}
- else {
- f.integer = -1;
- f.decimal = i;
+ else {
+ f.f64_integer = -1;
+ f.f64_decimal = i;
}
- return f;
+ return f;
}
-
-
================================================
aversive/modules/base/math/fixed_point/f64_inv.c (1.5.4.1 -> 1.5.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_inv.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_inv.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,9 +26,8 @@
f64 f64_inv(f64 f)
{
- if (F64_IS_ZERO(f))
- return F64_NAN;
+ if (F64_IS_ZERO(f))
+ return F64_NAN;
- return s64_to_f64( ((int64_t)0x7fffffffffffffff) / (f64_to_s64(f)/2) );
+ return s64_to_f64( ((int64_t)0x7fffffffffffffff) / (f64_to_s64(f)/2) );
}
-
====================================================
aversive/modules/base/math/fixed_point/f64_msb_mul.c (1.5.4.1 -> 1.5.4.2)
====================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_msb_mul.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_msb_mul.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -29,4 +29,3 @@
{
return (int32_t)(( f64_to_s64(a) * f64_to_s64(b)) >> 32);
}
-
================================================
aversive/modules/base/math/fixed_point/f64_mul.c (1.5.4.1 -> 1.5.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_mul.c,v 1.5.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_mul.c,v 1.5.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -27,8 +27,8 @@
/* about 300 us with a 16 Mhz quartz on an atm128 */
f64 f64_mul(f64 a, f64 b)
{
- return s64_to_f64( ( ((int64_t)(a.integer) * (int64_t)(b.integer)) << 32
) +
- (int64_t)(a.integer) * (int64_t)(b.decimal)
+
- (int64_t)(a.decimal) * (int64_t)(b.integer)
+
- ( ((int64_t)(a.decimal) * (int64_t)(b.decimal)) >> 32
) );
+ return s64_to_f64( ( ((int64_t)(a.f64_integer) *
(int64_t)(b.f64_integer)) << 32 ) +
+ (int64_t)(a.f64_integer) * (int64_t)(b.f64_decimal)
+
+ (int64_t)(a.f64_decimal) * (int64_t)(b.f64_integer)
+
+ ( ((int64_t)(a.f64_decimal) *
(int64_t)(b.f64_decimal)) >> 32 ) );
}
================================================
aversive/modules/base/math/fixed_point/f64_neg.c (1.4.4.1 -> 1.4.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_neg.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_neg.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -27,5 +27,5 @@
f64 f64_neg(f64 f)
{
- return s64_to_f64( -f64_to_s64(f) );
+ return s64_to_f64( -f64_to_s64(f) );
}
==================================================
aversive/modules/base/math/fixed_point/f64_print.c (1.4.4.1 -> 1.4.4.2)
==================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_print.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_print.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -25,9 +25,8 @@
void f64_print(f64 f)
{
- if(F64_IS_EQ(f, F64_NAN))
- printf("nan");
- else
- printf("%f",f64_to_double(f));
+ if(F64_IS_EQ(f, F64_NAN))
+ printf("nan");
+ else
+ printf("%f",f64_to_double(f));
}
-
=================================================
aversive/modules/base/math/fixed_point/f64_sqrt.c (1.5.4.2 -> 1.5.4.3)
=================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_sqrt.c,v 1.5.4.2 2007-06-12 16:18:43 zer0 Exp $
+ * Revision : $Id: f64_sqrt.c,v 1.5.4.3 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -41,24 +41,24 @@
f64 f64_sqrt(f64 f)
{
- uint64_t a,b,c,d;
+ uint64_t a,b,c,d;
- if (F64_IS_ZERO(f))
- return F64_ZERO;
+ if (F64_IS_ZERO(f))
+ return F64_ZERO;
- if (F64_IS_NEG(f))
- return F64_NAN;
+ if (F64_IS_NEG(f))
+ return F64_NAN;
- if(f.integer) {
- /* sqrt(a+b) = sqrt(a)*sqrt(1+b/a) */
- a=(uint64_t)(f.integer) << 32 ;
- b=(uint64_t)(f.decimal) << 32 ;
- c=u64_sqrt(a);
- d=u64_sqrt(0x100000000 + (b/a));
- return f64_mul(s64_to_f64( c<<16 ), s64_to_f64( d<<16 ));
- }
- else {
- b=(uint64_t)(f.decimal) << 32 ;
- return s64_to_f64(u64_sqrt(b));
- }
+ if(f.f64_integer) {
+ /* sqrt(a+b) = sqrt(a)*sqrt(1+b/a) */
+ a=(uint64_t)(f.f64_integer) << 32 ;
+ b=(uint64_t)(f.f64_decimal) << 32 ;
+ c=u64_sqrt(a);
+ d=u64_sqrt(0x100000000 + (b/a));
+ return f64_mul(s64_to_f64( c<<16 ), s64_to_f64( d<<16 ));
+ }
+ else {
+ b=(uint64_t)(f.f64_decimal) << 32 ;
+ return s64_to_f64(u64_sqrt(b));
+ }
}
================================================
aversive/modules/base/math/fixed_point/f64_sub.c (1.4.4.1 -> 1.4.4.2)
================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_sub.c,v 1.4.4.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: f64_sub.c,v 1.4.4.2 2008-05-10 15:06:26 zer0 Exp $
*
*/
@@ -26,6 +26,5 @@
f64 f64_sub(f64 a, f64 b)
{
- return s64_to_f64( f64_to_s64(a) - f64_to_s64(b) );
+ return s64_to_f64( f64_to_s64(a) - f64_to_s64(b) );
}
-
===================================================
aversive/modules/base/math/fixed_point/f64_to_s64.h (1.3.6.2 -> 1.3.6.3)
===================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: f64_to_s64.h,v 1.3.6.2 2007-05-23 17:18:11 zer0 Exp $
+ * Revision : $Id: f64_to_s64.h,v 1.3.6.3 2008-05-10 15:06:27 zer0 Exp $
*
*/
@@ -26,16 +26,16 @@
#if HOST_VERSION
/* not optimized, but will work with any endianness */
-static int64_t f64_to_s64(f64 f)
+static inline int64_t f64_to_s64(f64 f)
{
- return ( ((int64_t)(f.integer))<<32 ) | ((int64_t)(f.decimal));
+ return ( ((int64_t)(f.f64_integer))<<32 ) | ((int64_t)(f.f64_decimal));
}
#else
/* only for AVR, faster */
-static int64_t f64_to_s64(f64 f)
+static inline int64_t f64_to_s64(f64 f)
{
- return ( *(int64_t *)(void *)&f);
+ return f.u.s64;
}
#endif
===================================================
aversive/modules/base/math/fixed_point/s16_to_f16.h (1.3.6.1 -> 1.3.6.2)
===================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: s16_to_f16.h,v 1.3.6.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: s16_to_f16.h,v 1.3.6.2 2008-05-10 15:06:27 zer0 Exp $
*
*/
@@ -24,20 +24,21 @@
#ifdef HOST_VERSION
/* not optimized, but will work with any endianness */
-static f16 s16_to_f16(int16_t i)
+static inline f16 s16_to_f16(int16_t i)
{
- f16 f;
- f.integer = ((i) >> 8);
- f.decimal = (i);
- return f;
+ f16 f;
+ f.f16_integer = ((i) >> 8);
+ f.f16_decimal = (i);
+ return f;
}
#else
/* only for AVR, faster */
-static f16 s16_to_f16(int16_t i)
+static inline f16 s16_to_f16(int16_t i)
{
- return ( *(f16 *)(void *)&i);
+ f16 f;
+ f.u.s16 = i;
+ return f;
}
#endif
-
#endif
===================================================
aversive/modules/base/math/fixed_point/s32_to_f32.h (1.3.6.1 -> 1.3.6.2)
===================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: s32_to_f32.h,v 1.3.6.1 2006-11-26 21:06:01 zer0 Exp $
+ * Revision : $Id: s32_to_f32.h,v 1.3.6.2 2008-05-10 15:06:27 zer0 Exp $
*
*/
@@ -25,21 +25,22 @@
#ifdef HOST_VERSION
/* not optimized, but will work with any endianness */
-static f32 s32_to_f32(int32_t i)
+static inline f32 s32_to_f32(int32_t i)
{
- f32 f;
- f.integer = ((i) >> 16);
- f.decimal = (i);
- return f;
+ f32 f;
+ f.f32_integer = ((i) >> 16);
+ f.f32_decimal = (i);
+ return f;
}
#else
/* only for AVR, faster */
-static f32 s32_to_f32(int32_t i)
+static inline f32 s32_to_f32(int32_t i)
{
- return ( *(f32 *)(void *)&i);
+ f32 f;
+ f.u.s32 = i;
+ return f;
}
#endif
-
#endif
===================================================
aversive/modules/base/math/fixed_point/s64_to_f64.h (1.3.6.2 -> 1.3.6.3)
===================================================
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: s64_to_f64.h,v 1.3.6.2 2007-05-23 17:18:11 zer0 Exp $
+ * Revision : $Id: s64_to_f64.h,v 1.3.6.3 2008-05-10 15:06:27 zer0 Exp $
*
*/
@@ -27,19 +27,21 @@
#if HOST_VERSION
/* not optimized, but will work with any endianness */
-static f64 s64_to_f64(int64_t i)
+static inline f64 s64_to_f64(int64_t i)
{
- f64 f;
- f.integer = ((i) >> 32);
- f.decimal = (i);
- return f;
+ f64 f;
+ f.f64_integer = ((i) >> 32);
+ f.f64_decimal = (i);
+ return f;
}
#else
/* only for AVR, faster */
-static f64 s64_to_f64(int64_t i)
+static inline f64 s64_to_f64(int64_t i)
{
- return ( *(f64 *)(void *)&i);
+ f64 f;
+ f.u.s64 = i;
+ return f;
}
#endif
_______________________________________________
Avr-list mailing list
[email protected]
CVSWEB : http://cvsweb.droids-corp.org/cgi-bin/viewcvs.cgi/aversive
WIKI : http://wiki.droids-corp.org/index.php/Aversive
DOXYGEN : http://zer0.droids-corp.org/doxygen_aversive/html/
BUGZILLA : http://bugzilla.droids-corp.org
COMMIT LOGS : http://zer0.droids-corp.org/aversive_commitlog