paparazzi-devel
[Top][All Lists]
Advanced

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

[Paparazzi-devel] arm7 C double precision math


From: miles
Subject: [Paparazzi-devel] arm7 C double precision math
Date: Tue, 6 Oct 2009 19:00:18 -0500

Hi All,

I am running into an issue where it looks like the tiny2.11 (arm7tdmi) board can store double precision floating point numbers, but does not perform arithmetic (addition, multiplication) correctly.  Has anyone seen this, and/or resolved this before?

As a test, I have been trying to send a byte array of length 8 representing a double precision number over serial (via USB) to the Autopilot, use memcpy to copy that buffer to a variable of type double, and then do some simple addition, and send the result back over serial.  Below is the Autopilot code I am using.  Note that all of this works as expected for "float" variables, but seems to break for "double" variables! 

#include "std.h"
#include "init_hw.h"
#include "sys_time.h"
#include "led.h"
#include "usb_serial.h"

static inline void main_init( void );
static inline void main_periodic_task( void );

int main( void ) {
  main_init();
  while(1) {
    if (sys_time_periodic())
      main_periodic_task();
  }
  return 0;
}

static inline void main_init( void ) {
  hw_init();
  sys_time_init();
  led_init();
  VCOM_init();
  enableIRQ();
}

static inline void main_periodic_task( void ) {
  LED_TOGGLE(1);
 
  unsigned char buf[8];
  unsigned char buf2[8];
  double x;
  int c = 0;
  int c2 = 0;

  // read 8 bytes from serial (over USB)
  while (c < 8) {
    if (VCOM_check_available()) {
      buf[c] = VCOM_getchar();
      c++;
    }
  }
 
  // deserialize byte array to float:
  memcpy(&x, buf, 8);
  // modify float
  x = x + 1.0;
  // serialize float to byte array for sending
  memcpy(buf2, &x, 8);

  c2 = 0;
  while (c2 < 8) {
    VCOM_putchar(buf2[c2]);
    c2++;
  }
 
}

--
Miles Johnson

reply via email to

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