Project ideas from Hacker News discussions.

No portable way to detect string-to-float conversion errors in standard C

📝 Discussion Summary (Click to expand)

Theme 1 – Locale‑dependent number parsing is error‑prone
Many commenters warn that C’s strtod/sscanf obey the current locale, turning a decimal point into a comma in some environments and breaking code that assumes a dot.

  • “C number parsing functions are fundamentally broken, since they are locale‑dependend… one should avoid using them almost always and use std::from_chars …” – Panzerschrek
  • “That doesn’t detect overflows and underflows. Also changes based on locale, which is not thread safe…” – lelanthran
  • “Anything that isn’t C.UTF‑8 is totally broken anyway.” – tliltocatl

Theme 2 – Detecting conversion errors (overflow, underflow, invalid input) requires extra care
The basic APIs don’t reliably report problems; programmers suggest round‑trip checks, initializing variables to NaN/DBL_MAX, or writing wrappers that validate the result.

  • “That doesn’t detect overflows and underflows.” – lelanthran
  • “For extra reassurance, initialize foo to NaN or DBL_MAX or something, and verify that it is no longer equal to that value.” – CamperBob2
  • A round‑trip snippet that validates the conversion:
    c int s2d(double*restrict out,const char*restrict in){ char tmp[99]; int r,q=sscanf(in,"%lf%n",out,&r),s=sprintf(tmp,"%lf.",*out); return q&&!((r>s)||memcmp(in,tmp,r)||tmp[r]>'0'); } – geocar

Theme 3 – C’s error‑handling model (global errno) is awkward; developers prefer functions that return error information directly
The reliance on a global errno variable is criticized as error‑prone and non‑thread‑safe, with many advocating for tuple returns, structs, or sum‑type‑style error handling.

  • “errno is a worse mistake than null pointers in general.” – raverbashing
  • “[double x, errno_t errno] = strtod(s, nullptr); … Instead, we’re stuck with 'check if the return value is -1 and if it is, check the global variable errno' …” – Joker_vD
  • Demonstrates a manual struct return that bundles value and error code. – gucci-on-fleek (code example)
  • “Sometimes I wish we could get to a timeline where … sum types/tagged unions …” – muvlon

🚀 Project Ideas

Generating project ideas…

Locally-Independent Number Parser (LINP)

Summary

  • A header‑only C/C++ library that parses numeric strings without relying on locale‑dependent libc functions, returning a struct containing the parsed value and an explicit error code.
  • Eliminates errno globals and locale surprises, offering a fast, thread‑safe from_chars‑based API for double, int, and uint parsing.

Details

Key Value
Target Audience Systems programmers, library authors, and anyone needing reliable number parsing in multithreaded or embedded contexts
Core Feature Locale‑agnostic parse functions (linp_parse_double, linp_parse_int64, …) returning {value, error} with error values like NO_ERROR, INVALID_INPUT, OVERFLOW
Tech Stack C11 (or C++17) – header only, uses std::from_chars under the hood; optional CMake build
Difficulty Medium
Monetization Hobby

Notes

  • HN commenters complained about sscanf/strtod locale dependence and errno shenanigans (e.g., “sscanf has locale things that make it include implementation‑defined behaviour”; “errno is a worse mistake than null pointers”). LINP directly addresses those pain points.
  • Provides a drop‑in replacement that can be vendored into projects, encouraging discussion on safer numeric I/O and potentially inspiring similar wrappers for other libc APIs.

Errno‑Free Wrapper Generator (EFWG)

Summary

  • A command‑line tool that reads a list of C library functions (e.g., strtod, malloc, fopen) and generates ergonomic wrapper functions that return a {value, error} struct/tuple, eliminating the need to check the global errno.
  • Generates both C23‑style struct returns and macro‑based alternatives for older standards, letting developers write cleaner, more explicit error handling.

Details

Key Value
Target Audience C/C++ developers building libraries or applications who want to avoid errno‑checking boilerplate
Core Feature Automatic generation of wrapper APIs that encapsulate error info, with configurable return styles (struct, macro, or C++ std::expected)
Tech Stack Python 3.9+, Jinja2 templates for code generation, optional libc header parsing via libclang
Difficulty Medium
Monetization Hobby

Notes

  • The thread highlighted the ergonomic pain of errno: “errno is a worse mistake than null pointers” and showed examples of manual struct returns to avoid it. EFWG automates that pattern, saving boilerplate and reducing mistakes.
  • Generated wrappers can be easily integrated into existing codebases, sparking conversation about better error‑handling idioms in C and encouraging adoption of sum‑type‑like returns.

FloatFormat Playground (FFP)

Summary

  • An interactive web service (with optional desktop/local mode) that lets developers encode, decode, and visualize numbers in multiple floating‑point representations (IEEE‑754 binary32/64, DEC64, posit, VAX, etc.) and observe precision, rounding, and conversion differences.
  • Includes a C/C++ library with constexpr conversion functions and Python/Numpy bindings for experimentation in algorithms or teaching.

Details

Key Value
Target Audience Numerics researchers, compiler/firmware engineers, educators, and curious programmers exploring alternative FP formats
Core Feature Real‑time bit‑pattern view, error analysis (ulp, relative error) when converting between formats, and configurable rounding modes
Tech Stack Frontend: TypeScript + React + WebAssembly (compiled C core); Backend (optional): FastAPI; Core library: C++20 with constexpr functions; Python bindings via pybind11
Difficulty High
Monetization Revenue-ready: SaaS subscription $9/month for private workspaces & API access; free tier for public playground

Notes

  • The discussion included links to DEC64 and VAX floating point, with comments like “Sometimes I wish we could get to a timeline where the FPU format standards have something like Crockford’s DEC64 … Simpler & consistent math ought not to be this hard.” FFP lets users experiment with those ideas instantly.
  • By exposing the trade‑offs of alternative formats, FFP can fuel HN debates, help decide when a custom format is worthwhile, and serve as a teaching aid for floating‑point concepts.

Read Later