Skip to content

Instantly share code, notes, and snippets.

View SebastianWilke's full-sized avatar

Sebastian Wilke SebastianWilke

View GitHub Profile
@SebastianWilke
SebastianWilke / dotprod.cpp
Last active April 2, 2023 12:36
C++ compile time dot product using template metaprogramming
#include <array>
#include <cstddef> // std::size_t
template <std::size_t N, std::size_t M = 0U>
struct dotprod {
template <typename InputIt1, typename InputIt2, typename T>
constexpr static T sum(InputIt1 u, InputIt2 v, T init) {
const T uv_m{*(u + M) * T{*(v + M)}};
return uv_m + dotprod<N, M + 1U>::sum(u, v, init);
}
@SebastianWilke
SebastianWilke / pi.c
Last active October 18, 2020 23:52
functions to calculate sin, cos, exp and pi in c
// 3.1415926535897932384626433832795028841971693993751058209749445923
#include <stdio.h>
#include <stdint.h>
double pi_series_representation (int N)
{
double result = 0.0;
int8_t sign = 1;