Pages: [1]   Go Down
Author Topic: Double variable 8 bytes  (Read 1869 times)
0 Members and 1 Guest are viewing this topic.
Selvazzano Dentro - Padova
Offline Offline
Edison Member
*
Karma: 45
Posts: 1553
"Chi sa fa, chi non sa insegna"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 95
Posts: 4094
CODE is a mass noun and should not be used in the plural or with an indefinite article.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
long long myInt1;
unsigned long long myInt2;
Logged

MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19306
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 227
Posts: 14024
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Rob Tillaart

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

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13072
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Correction...

long long sort of works but and is very slow

The expression is ((Value * Numerator) + (Denominator - 1)) / Denominator .  Half the time the result is off by one.

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

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 227
Posts: 14024
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
#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
Logged

Rob Tillaart

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

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13072
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Naw.  I just got "lucky".
Logged

Pages: [1]   Go Up
Jump to: