Repository navigation
contrib.xmp tracker-module player; std.string to_float parses to 64 bits - #3882
Merged
Merged
Conversation
contrib.xmp plays MOD, S3M, XM, IT, MED and the other formats libxmp reads, through std.audio. It is full libxmp (the player, every loader, ProWizard and the depackers), and std.audio stays the only audio output. API (contrib/xmp/module.ae): load(data, length) / load_file(path) -> ptr!, free; title, format, channels, patterns, orders, instruments, samples, duration_ms; start(p, rate), render(p, frames) -> string! (interleaved signed 16-bit stereo), render_all, seek_ms, set_order, position_ms, order, row, looping, ended; and through std.audio, sound(p, rate) (render_all into audio.load_pcm) and stream_open(p, rate, frames) + pump(p, src) (blocks pushed into an audio.stream_open ring). Each player owns its libxmp context and buffers; nothing runs on a thread of its own. libxmp's source is handled as contrib.sqlite's amalgamation is: contrib/xmp/libxmp.lock pins libxmp 4.7.4's GitHub release tarball by URL and SHA-256 (the checksum libxmp publishes for the release); scripts/fetch-libxmp.sh downloads it, refuses a mismatch, and extracts include/, src/ (no src/lite) and the licence into the gitignored contrib/xmp/libxmp/, with sources.txt taken from Makefile.vc's object lists. No configure or CMake. - make contrib (tests/scripts/contrib_build.sh) compiles those sources into build/contrib/libxmp.a beside libaether_xmp.a, cached by release, compiler and flags, and falls back to the system libxmp when the source cannot be fetched (LIBXMP_SYSTEM=1 forces it). - ae build --target compiles libxmp for the target (ae_vendored_xmp in tools/ae_cross.c, one cache slot per object), unless a CROSSBUILD_SYSROOT stages the archives; a binary release with no archives compiles it for the host the same way (tools/ae.c). - Release staging fetches the source and ships it, with libxmp's COPYING and contrib/xmp/NOTICE, plus the two archives; the install trim keeps the source; CI fetches it and runs the spec (valgrind on Linux, Windows) and the cross build. Tests: contrib/xmp/test_xmp.ae writes a ProTracker MOD and a Fast Tracker II XM byte by byte and asserts on the rendered PCM (sound, silence, exact length, seek and loop positions, refusals), with the std.audio half on the headless engine; tests/integration/libxmp_fetch (the fetch script, offline) and tests/integration/xmp_vendored_cross (zig). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Aether's `float` is 64-bit (C double), but string.to_float parsed with
strtof and widened the 32-bit result, so it returned about seven
significant digits dressed as a double:
a, _ = string.to_float("0.1")
println(string.string_from_double(a)) // 0.10000000149011612
c, _ = string.to_float("16777217")
println(string.string_from_double(c)) // 16777216
to_float now parses with strtod, correctly rounded to binary64, with the
syntax to_double accepted (hex constants, inf/nan spellings, the same
errors). string_to_float_raw writes a double; string_get_float parses at
64 bits rather than widening a float.
to_double is kept, as a call to to_float, so the two always agree; the
externs string_try_double and string_get_double are kept the same way,
as string_try_float and string_get_float under their old names. Each
carries a TODO: delete it once nothing in the aether-lang-dev org's repos
or in friends-and-family repos uses it. Not a breaking change. Every
caller in this tree moves to to_float (benchmarks, contrib jq and liquid,
std cbor, decimal and jsonpath, the tests and the docs), so the in-tree
count of to_double callers is zero. decimal.to_double is a
decimal-to-float conversion, not a parse, and keeps its name.
string_to_double_raw, which nothing outside std.string used, is removed.
string.to_f32(s) -> (f32, string) is the 32-bit parse: strtof, rounded
once straight to binary32, returning a real f32 (C float), with past the
f32 range an overflow error; externs string_to_f32_raw, string_try_f32,
string_get_f32. No caller in the tree wanted 32-bit rounding; to_f32
keeps the locale-pinned strtof path (aether_c_strtof, with its msvcrt
handling) reachable and tested.
Tests whose expectations encoded the 32-bit parse now call to_f32:
test_string_parse_hex_float and test_string_parse_float_halfway (their
float-bits checks, e.g. 0x1.000001p0 -> 1.0 and the float-tie inputs),
test_string_parse_inf_nan, test_string_embedded_nul,
test_string_to_number_widths and tests/syntax/test_string_parse_tuple;
their to_double checks become to_float checks. No golden file changed.
New tests/regression/test_string_to_float_64_bit.ae, failing before the
fix: to_float("0.1") equals the literal 0.1 with bits 3fb999999999999a,
"16777217" reads back as 16777217, 17-significant-digit values
(pi, DBL_MAX, DBL_MIN, ...) round-trip through string_from_double to the
same bits, "1e39" is in range; to_f32 rounds like strtof ("0.1" ->
3fb99999a0000000 widened, "16777217" -> 16777216, "1e39" overflows);
to_double equals to_float bit for bit and still rejects trailing garbage.
The LSP completion list gains to_f32 and marks to_double slated for
deletion; docs/api and the stdlib index regenerated; changelog fragment
under changed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two commits: a new contrib module and a std.string precision fix.
Commit 1: cfc4814 contrib.xmp, a tracker-module player for std.audio
A new contrib module over full libxmp (MOD, S3M, XM, IT, MED and the other formats libxmp reads), playing through std.audio. It has no audio output of its own.
a25583aa3b031c78ba0b4e83387fa596fb05742622e60f60d1540ee2af79b8d9(matches upstream's release notes and GitHub's digest), pinned incontrib/xmp/libxmp.lock.scripts/fetch-libxmp.sh, and compiled from its source list without configure, the same way contrib/sqlite handles its amalgamation.ae build --target. Release archives ship the source and NOTICE (MIT, Claudio Matsuoka and Hipolito Carraro Jr).load/load_file/free; info (title,format,channels,duration_ms, …);start,render(16-bit stereo),render_all,seek_ms,set_order,position_ms,looping,ended.sound(p, rate)(whole module viaload_pcm) andstream_open+pump(a stream ring).contrib/xmp/test_xmp.aehas 20 tests on a MOD and an XM written byte by byte, covering sound, silence, exact length, seek, loop, error paths and std.audio headless. It fails on five deliberate mutations. Alsotests/integration/libxmp_fetchandxmp_vendored_cross.CC=gcc make cipassed;make test-ae2397 passed / 0 failed; valgrind contrib-check, veneer under -Werror, ASan+UBSan,release_contrib_c_modules, and the xmp and sqlite cross builds for x86_64- and aarch64-linux-musl (qemu) all pass.leaks0.gmake test786/786;gmake test-ae2381 passed, 1 failed (cross_emit_lib, a cold-zig-cache timeout, not using xmp); spec valgrind-clean.--fair-sched, which FreeBSD's valgrind refuses (Linux-only in CI).ae_vendored_xmpcompiles one file at a time, about 70 s per target. Parallelise it?Commit 2: 8ed403b
std.string:
to_floatparses to 64 bits, correctly rounded;to_f32added (8ed403b)Bug. Aether's
floatis 64-bit (Cdouble);f32is the 32-bit type.string.to_floatparsed withstrtofand widened the 32-bit result, so it returned about seven significant digits dressed as a double. The C side's comment called this deliberate ("to_float's contract"), but nothing in the language makesfloat32-bit.Repro (0.947.0):
Fix.
to_float(s) -> (float, string)parses withstrtod(locale-pinnedaether_c_strtod), correctly rounded to binary64, with exactly the syntaxto_doubleaccepted: hexadecimal constants,inf/infinity/nanin any case with a sign, the same whitespace and error rules.string_to_float_rawnow writes adouble;string_get_floatparses at 64 bits instead of widening a float.to_doubleis kept, not removed. This is not a breaking change. It is nowreturn to_float(s), so the two cannot drift. The externsstring_try_double/string_get_doubleare kept the same way, as the old names ofstring_try_float/string_get_float, because downstream repos call them directly. Each carries a TODO: delete it once nothing in the aether-lang-dev org's repos or in friends-and-family repos uses it.string_to_double_rawis removed: nothing outside std.string used it.string.to_f32(s) -> (f32, string):strtof, rounded once and directly to binary32, returning a realf32(Cfloat). A value past the f32 range is an overflow error. Externs:string_to_f32_raw,string_try_f32,string_get_f32. No in-tree caller wanted 32-bit rounding.to_f32keeps the locale-pinnedstrtofpath (aether_c_strtof, with its msvcrt handling) reachable and tested.to_doubletoto_float, so the in-tree count is now 0. That covers about 34 call sites across the benchmarks,contrib/jq,contrib/templating/liquid,std/cbor,std/decimal,std/jsonpath(string.get_double), the tests, the LSP completion list anddocs/stdlib-reference.md.decimal.to_doubleis a conversion from decimal to float, not a parse, so it keeps its name. The existingto_floatcallers (liquid, schema, resp, message, language) all wanted full precision. They now get it.docs/apiand the stdlib index are regenerated, andcheck-docspasses. Changelog fragment:changed/to-float-64-bit.Tests.
New
tests/regression/test_string_to_float_64_bit.ae. Run against the old code, it failed 6 checks. It checks:to_float("0.1") == 0.1, bits3fb999999999999a;"16777217"reads back as 16777217;string_from_doubleto the same bits, and pi has the exact bits;"1e39"is in range;to_f32rounds likestrtof:"0.1"gives3fb99999a0000000widened,"16777217"gives 16777216, and"1e39"is an overflow error;to_doubleequalsto_floatbit for bit on decimal, hex, infinity and whitespace-padded input, and still rejects trailing garbage.Tests whose expectations encoded the 32-bit parse now call
to_f32. Theirto_doublechecks becameto_floatchecks:test_string_parse_hex_float(e.g.0x1.000001p0 -> 1.0);test_string_parse_float_halfway(the float-tie inputs from Windows: with msvcrt WinLibs GCC 14.2 (mingw-w64 12) the runtime compiled from source does not link (__imp__strtof_l, aether_locale_num.c) #3818);test_string_parse_inf_nan;test_string_embedded_nul;test_string_to_number_widths;tests/syntax/test_string_parse_tuple.No golden file changed.
Lanes.
make test-ae2362 passed, 0 failed, 55 skipped.make check-docspasses.batch/nov26btree: build, every std.string / decimal / cbor test andcontrib/xmp/test_xmp.ae(viacontrib_check.sh, aftermake contrib MODULES=xmp) pass.gmake test786/786.gmake test-ae2381 passed, 2 failed, 34 skipped. Both failures pass when run alone:crypto_tls13_external_psk, andcross_emit_lib(420 s timeout under load, 78 s alone).gmake test786/786, and all the string tests pass.CC=gcc make cicompiled clean under-Werrorand ran C units 788/788. Itstest-aestage had 2395 passed, 2 failed, 20 skipped. The two failures werecross_emit_libandcross_linux_musl, both hitting the 420 s timeout on a box at load average 7+ shared with other agents; neither touches std.string. - ae-x64 (Ubuntu 22.04 x86_64):make test-ae2397 passed, 0 failed; final tree built with gcc (compiler -Werror) and all 62 string tests pass.Downstream callers to migrate to
to_floatbeforeto_doubleis deleted (grep of~/scm/*/excluding aether and not-ours; nothing breaks today):string.string_try_double/string.string_get_double(the externs) insrc/builtins.ae,engine.ae,evaluate.ae,library.ae,program.ae,values.ae(about 30 lines).string.get_double/try_doubleinsrc/ae3d/loader/module.ae,tools/drive_editor.ae,tools/check_coplanar.ae;string.to_doubleintests/test_loader.aeand the vendoreddeps/aephysics/aephysics/files/module.ae.aephysics/files/module.ae.vg/(29 files:module.ae,README.md,backend/gtk.ae,chart/*,geom/*,grammar/*,raster/rasterize.ae,svg/*,test/*) andapps/analog_clock_png.aevg/tsemit.ae,tests/spec_aevg_parity.ae.integration/climate_interop/module.ae.sql/module.ae,sql/mysql/mysqlproto/module.ae.🤖 Generated with Claude Code