codata.zig
is a Zig library providing physical constants and reference data based on the CODATA recommended values.
This library aims to provide accurate, up-to-date physical constants for scientific and engineering calculations in Zig, following the latest CODATA recommendations.
- Standard physical constants (e.g., Planck constant, speed of light, elementary charge)
- Easy-to-use Zig API
- Values sourced from CODATA and NIST
Fetch this repository :
$ zig fetch --save git+https://github.com/astrozig/codata.zig
Add it to your build.zig
:
const std = @import("std");
pub fn build(b: *std.Build) void {
// -- snip --
+ const codata_dep = b.dependency("codata_zig", .{
+ .target = target,
+ .optimize = optimize,
+ });
// Where `exe` represents your executable/library to link to
+ exe.root_module.addImport("codata", codata_dep.module("codata"));
// -- snip --
}
const codata = @import("codata");
pub fn main() !void {
const c = codata.speed_of_light_in_vacuum; // Example
// Use constants in calculations
}
Generate new constants from src file:
zig run src/gen.zig -- data/CODATA_2022_adjustment.txt