Skip to content

Instantly share code, notes, and snippets.

// xoroshiro128+
uint64_t rng_state[2];
#if defined(_MSC_VER)
#define TO_FP32 (1.f/16777216.f)
#else
#define TO_FP32 0x1p-24f
#endif
<!DOCTYPE html><html><head><meta charset='utf-8'><title>Plot</title><script src='https://cdn.plot.ly/plotly-latest.min.js'></script><script type='text/javascript' src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script></head><body>
<style>body{margin:auto;padding:15px;text-align:justify;line-height:140%; -webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-size:14px;font-smoothing:antialiased;color:#222;font-family:Roboto, sans-serif;}</style><style>h1{border-bottom: 2px solid #666; color: #333; padding: 20px 0 8px }</style><style>h2{border-bottom: 1px solid #888; color: #555; padding: 20px 0 4px }</style></style><style>div.funclist{font-size: 12px}</style><h1>Example report using arctangent</h1>
This is overkill 'reporting' as demo. Actual intended use is to quickly visualize a small set of approximations over the domain. The script builds the HTML and can automatically open the results in a brower. A fair number of plot traces are so close they ove
@Marc-B-Reynolds
Marc-B-Reynolds / gist:80ceaf0b4724ad428d86d7c025d0d9ad
Last active December 7, 2016 10:40
2x32-bit xorshift/weyl sequence
// 1 dep-chain (assuming state words in reg) to result.
// DON'T USE ME UNLESS YOUR PARINOID AND
// USING SOMETHING MORE EXPENSIVE (actually inferior
// to some other formulations...period is only 2^32-1)
// Zero is illegal for both state words.
typedef struct { uint32_t s[2]; } rng_state_t;
// smallcrush: passes
// crush: 1 systematic failure = 72 LinearComp, r = 29
@Marc-B-Reynolds
Marc-B-Reynolds / averot.c
Last active June 27, 2019 12:26
empirical test of average rotation angle of uniform rand rotations
// Public Domain under http://unlicense.org, see link for details.
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "xmmintrin.h"
@Marc-B-Reynolds
Marc-B-Reynolds / foo.c
Created March 19, 2019 17:13
tweet dep break-up details
// SEE: https://lemire.me/blog/2019/03/19/the-fastest-conventional-random-number-generator-that-can-pass-big-crush/
__uint128_t g_lehmer64_state;
uint64_t lehmer64() {
uint64_t r = (g_lehmer64_state >> 64);
g_lehmer64_state *= 0xda942042e4dd58b5;
return r;
}
@Marc-B-Reynolds
Marc-B-Reynolds / foo.txt
Created April 11, 2019 09:28
factor PI into two doubles A*B
(*
Pi correctly rounded to 106 digits via sollya:
> display=dyadic!;
> round(Pi,106,RN);
63719069007931157819013617823235b-104
*)
s = 63719069007931157819013617823235
(* prime factors of 's' and nearby integers *)
@Marc-B-Reynolds
Marc-B-Reynolds / gist:948b550fbcba3726da8bdb680b50e440
Created April 13, 2019 22:37
factor Pi into two singles A*B
(* Mathematica source
same method as the previous gist for double. This validates that the constants giving here are optimal:
https://stackoverflow.com/questions/26692859/best-machine-optimized-polynomial-minimax-approximation-to-arctangent-on-1-1
*)
(* round(Pi,48,RN) *)
s = 221069929750889
(* prime factors of 's' and nearby integers *)
f0 = FactorInteger[s];
@Marc-B-Reynolds
Marc-B-Reynolds / foo.c
Created June 28, 2019 12:55
RU(sqrt(x)) & RD(sqrt(x)) in round-to-nearest
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
inline uint32_t f32_to_bits(float x)
{
uint32_t u; memcpy(&u, &x, 4); return u;
}
#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include "gdef.h"
#include "swrite.h"
#include "bbattery.h"
#include "scomp.h"
#include "swalk.h"
#include "svaria.h"
@Marc-B-Reynolds
Marc-B-Reynolds / approx.sollya
Last active January 6, 2025 05:56
sollya script and output for sincospi in both single and double precision
/* -*- mode: c; -*- */
// create primary range approximations of sin(pi x) and cos(pi x) for x on [-1/4,1/4]
// both for single and double precision
R = [0;1/4];
T = floating;
E = relative;
B = [|24...|];