#define WOKWI // Uncomment if running on Wokwi RP2040 emulator.
#include <stdio.h>
#include <stdlib.h>
#include "pico/float.h" // Required for using single-precision variables.
#include "pico/double.h" // Required for using double-precision variables.
#include <math.h>
//#include "pico/stdlib.h"
/**
* @brief EXAMPLE - HELLO_C
* Simple example to initialise the IOs and then
* print a "Hello World!" message to the console.
*
* @return int Application return code (zero for success).
*/
float wallisProductFloat(int iterations);
double wallisProductDouble(int iterations);
float wallisProductFloat(int iterations){
float result = 1;
for (int i = 1; i <= iterations; ++i) {
float number = 4 * i * i;
result *= number / (number - 1);
}
return result * 2;
}
double wallisProductDouble(int iterations){
double result = 1;
for (int i = 1; i <= iterations; ++i) {
double number = 4 * i * i;
result *= number / (number - 1);
}
return result * 2;
}
int main() {
#ifndef WOKWI
// Initialise the IO as we will be using the UART
// Only required for hardware and not needed for Wokwi
stdio_init_all();
#endif
// Print a console message to inform user what's going on.
printf("Wallis Product Float is %f", wallisProductFloat(10000));
printf("Wallis Product Double is %f", wallisProductDouble(10000));
// Returning zero indicates everything went okay.
return 0;
}