Skip to content

Instantly share code, notes, and snippets.

View jonas-s-s-s's full-sized avatar
🕳️

Jonas jonas-s-s-s

🕳️
View GitHub Profile
@jonas-s-s-s
jonas-s-s-s / dtoa.cpp
Created December 4, 2024 12:11
C++ dtoa no dependency
// Modified algorithm from: http://git.musl-libc.org/cgit/musl/tree/src/stdio/vfprintf.c#n208
#include <cstdio>
namespace
{
// default precision for floating-point conversion
constexpr int DEFAULT_PRECISION = 6;
inline void copy_str(char *dest, const char *src)
{
@jonas-s-s-s
jonas-s-s-s / dtoa.cpp
Created December 4, 2024 11:44
C++ style dtoa / double to string
// Example program
#include <cstdio>
#include <cstring>
// Replacing macros with constexpr or inline functions
constexpr int DEFAULT_PRECISION = 6; // Default precision for floating-point conversion
// Inline functions for max and min
template <typename T>
inline T max(T a, T b) {
@jonas-s-s-s
jonas-s-s-s / dtoa.c
Created December 4, 2024 11:37
dtoa / double to string
// Logic form: http://git.musl-libc.org/cgit/musl/tree/src/stdio/vfprintf.c#n208
// Example program
#include <cstdio>
#include <math.h>
#include <limits.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@jonas-s-s-s
jonas-s-s-s / EventfdQueue.h
Created September 22, 2024 01:33
Thread safe queue using eventfd
//
// Created by J. on 12.11.2023.
//
#pragma once
#include <mutex>
#include <queue>
#include <sys/eventfd.h>