I had a couple of boards that I had bought for a great price but never used, so I added them to the lineup.
I also made a few changes to the sketch.
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__)
#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#define _ARDUINO_AVR_ 1
#elif defined(ARDUINO) && defined(__SAM3X8E__)
#define _ARDUINO_DUE_ 1
#elif defined(__RX__)
#include <rxduino.h>
#define _GR_SAKURA_ 1
#elif defined(__RL78__)
#include <RLduino78.h>
#define _GR_KURUMI_ 1
#elif defined(ENERGIA)
#include <Energia.h>
#if defined(__MSP430G2452__) || defined(__MSP430G2553__)
#define _LAUNCHPAD_VALUELINE_ 1
#elif defined(__LM4F120H5QR__)
#define _LAUNCHPAD_STELLARIS_ 1
#error unknown target.
#define DIGITS 1000
#define BUFBITS (int(/*log(10)/log(2)*/3.32192809489 * DIGITS) + 1)
#if !_LAUNCHPAD_VALUELINE_
static uint8_t buf[(BUFBITS + 7) / 8];
static uint8_t pi_dig16(unsigned n);
void setup()
{
Serial.begin(9600);
unsigned long start = millis();
for (int i = 0; i < ((BUFBITS + 3) / 4); i++) {
if ((i & 1) == 0) {
buf[i / 2] = pi_dig16(i) << 4;
} else {
buf[i / 2] |= pi_dig16(i);
}
pi_dig16(i);
unsigned long time = millis() - start;
Serial.println("PI = 3.");
int c = 0;
for (int i = 0; i < DIGITS; i++) {
for (int j = (BUFBITS + 7) / 8 - 1; j >= 0; j--) {
c += 10 * buf[j];
buf[j] = c % 256;
c /= 256;
Serial.print(c);
if ((i + 1) == DIGITS || i % 50 == 49) {
Serial.println();
} else if (i % 10 == 9) {
Serial.print(" ");
Serial.print(time);
Serial.println("msec.");
void loop()
#define main _main
#if _ARDUINO_AVR_
#define lrintf lrint
#define floorf floor
#undef __AVR__
#if _GR_SAKURA_
#define _STDINT_H
#if _LAUNCHPAD_VALUELINE_
#define lrintf (int)rintf
#define stdout (0)
#define fputc(x, y) ((void)x, (void)y)
#define fflush(x) ((void)x)
/*
http://www.mikrocontroller.net/articles/4000_Stellen_von_Pi_mit_ATtiny2313
*/
Results:
Random comments:
I recently found out that in the RL78 compiler comparison, the float process was replaced with a fixed decimal point, so I decided do some tests using the fixed decimal point as well.
The results are as follows:
Random comments
This is a translation of a post from http://japan.renesasrulz.com.
All the code used and the results are thoroughly documented.
Although original post is no longer available, the metrics are an excellent comparison.
Mike Clements
RenesasRulz Moderator