Go Down

Topic: Double variable 8 bytes (Read 1 time) previous topic - next topic

cyberhs

I read that DUE use "true" Double variables 8 byte.

I wish that this feature would be disposable for UNO and MEGA too. 

Jack Christensen

I believe a "long long" is 64 bits, but I haven't had occasion to try them myself:

Code: [Select]
long long myInt1;
unsigned long long myInt2;
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Nick Gammon

The Uno and Mega have less memory, and less program memory, so supporting double could take quite a lot of that. Bearing in mind most readings are only around 4 significant digits (eg. analog read: up to 1023), the need for 15 to 17 significant digits is probably not that great. However you can always use "big numbers":

http://www.gammon.com.au/forum/?id=11519

robtillaart

Quote
I believe a "long long" is 64 bits, but I haven't had occasion to try them myself:


long long works but is very slow, if it is for counting (e.g. in interrupts) one can better use a "high" long and a "low" long and when the low overflows increment the high.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Coding Badly


Correction...

long long sort of works but and is very slow


The expression is[font=Courier New] ((Value * Numerator) + (Denominator - 1)) / Denominator [/font].  Half the time the result is off by one.

If memory is a concern, [unsigned] long long division pulls in 2K worth of code.

robtillaart

Quote
Half the time the result is off by one.

did not encounter that but you probably have more long long experience as I have.

Added a patch for (unsigned) long long in print.cpp some time ago.

print.h
Code: [Select]

#ifdef SUPPORT_LONGLONG
size_t println(int64_t, int = DEC);
size_t print(int64_t, int = DEC);
size_t println(uint64_t, int = DEC);
size_t print(uint64_t, int = DEC);
#endif


print.cpp
Code: [Select]

#ifdef SUPPORT_LONGLONG

size_t Print::println(int64_t number, int base)
{
  size_t n = 0;
  n += print(number, base);
  n += println();
  return n;
}

size_t Print::print(int64_t number, int base)
{
  size_t n = 0;
  if (number < 0)
  {
    write('-');
number = -number;
n++;
  }
  n += print((uint64_t)number, base);
  return n;
}

size_t Print::println(uint64_t number, int base)
{
  size_t n = 0;
  n += print((uint64_t)number, base);
  n += println();
  return n;
}

size_t Print::print(uint64_t number, int base)
{
  size_t n = 0;
  unsigned char buf[64];
  uint8_t i = 0;

  if (number == 0)
  {
    n += print((char)'0');
    return n;
  }
 
  if (base < 2) base = 2;
  else if (base > 16) base = 16;

  while (number > 0)
  {
    uint64_t q = number/base;
    buf[i++] = number - q*base;
    number = q;
  }
 
  for (; i > 0; i--)
    n += write((char) (buf[i - 1] < 10 ?
      '0' + buf[i - 1] :
      'A' + buf[i - 1] - 10));
 
   return n;
}
#endif
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Coding Badly

...but you probably have more long long experience as I have.


Naw.  I just got "lucky".

Go Up