Add float scalar support for geo and approximate measurements #5

Open
opened 2026-08-02 18:12:45 +00:00 by lost-rob0t · 0 comments
lost-rob0t commented 2026-08-02 18:12:45 +00:00 (Migrated from github.com)

Problem

STAR-LANG-RESEARCH-009 incorrectly rejected all floating-point JSON values. The current Star-CL fixture models latitude, longitude, altitude, and accuracy as decimal, but these are approximate geospatial measurements and should be represented as floats.

Numeric model

  • integer: exact integer, encoded as a JSON number
  • float: finite IEEE-754 binary64 value, encoded as a JSON number
  • decimal: exact base-10 value, encoded as a canonical JSON string

Use float for coordinates, altitude, accuracy, measurements, and scientific values where approximate arithmetic is expected. Keep decimal for money, contractual rates, fixed-scale quantities, and other exact values.

Canonical float serialization decision

  • Normative runtime: the Nix-pinned SBCL used by Star-Lang CI. A Star-Lang float is a Common Lisp double-float; the implementation must verify that the host representation is IEEE-754 binary64. Python and TypeScript are generated binding targets, not canonicalization runtimes.
  • Normative wire contract: RFC 8785 §3.2.2.3, including the exact binary64 serialization vectors in Appendix B.
  • Conversion algorithm: a pure Common Lisp implementation of Ryu for binary64-to-shortest-decimal conversion, using round-to-nearest, ties-to-even. Apply the RFC 8785/ECMAScript presentation rules after digit generation; do not use implementation-dependent Common Lisp printer output.
  • Emit lowercase e, the RFC/ECMAScript fixed-versus-exponent thresholds and exponent spelling, with no redundant digits or zeros.
  • Encode both positive and negative zero as JSON 0.
  • Reject NaN and positive/negative infinity before conversion.
  • Canonicalization must not invoke Node, Python, an FFI helper, or an external process.

Required implementation

  • Add float as a supported scalar base type.
  • Verify at initialization/test time that SBCL double-float has binary radix, 53-bit precision, and the IEEE-754 binary64 exponent range.
  • Add one canonical float encoder in star-canonical-json; route every manifest, wire-envelope, fixture, and generated-contract serialization path through it.
  • Implement the pure Common Lisp Ryu binary64 conversion and RFC 8785 presentation rules.
  • Accept only finite binary64 values; reject NaN and positive/negative infinity with structured conditions.
  • Canonicalize negative zero to JSON 0.
  • Map Star-Lang float to Common Lisp double-float, Python float, and TypeScript number.
  • Keep Star-Lang decimal mapped to exact canonical strings.
  • Migrate latitude and longitude scalar bases from decimal to float.
  • Migrate geo.alt and geo.accuracy from decimal to float.
  • Add exact-output tests for every RFC 8785 Appendix B vector.
  • Add bit-preserving round-trip tests for finite values, including max finite, min normal, min subnormal, precision-sensitive values, and the fixed/exponent notation boundaries.
  • Add NaN/infinity rejection, positive/negative-zero normalization, and generated Python/TypeScript binding tests.
  • Add CI guards against falling back to host float printers or a second runtime.

Research status

This issue is the accepted implementation amendment for the numeric portion of STAR-LANG-RESEARCH-009. Synchronize that research document with this decision before marking the research ledger complete; implementation may proceed against this issue now.

## Problem `STAR-LANG-RESEARCH-009` incorrectly rejected all floating-point JSON values. The current Star-CL fixture models latitude, longitude, altitude, and accuracy as `decimal`, but these are approximate geospatial measurements and should be represented as floats. ## Numeric model - `integer`: exact integer, encoded as a JSON number - `float`: finite IEEE-754 binary64 value, encoded as a JSON number - `decimal`: exact base-10 value, encoded as a canonical JSON string Use `float` for coordinates, altitude, accuracy, measurements, and scientific values where approximate arithmetic is expected. Keep `decimal` for money, contractual rates, fixed-scale quantities, and other exact values. ## Canonical float serialization decision - **Normative runtime:** the Nix-pinned **SBCL** used by Star-Lang CI. A Star-Lang `float` is a Common Lisp `double-float`; the implementation must verify that the host representation is IEEE-754 binary64. Python and TypeScript are generated binding targets, not canonicalization runtimes. - **Normative wire contract:** [RFC 8785 §3.2.2.3](https://www.rfc-editor.org/rfc/rfc8785.html#section-3.2.2.3), including the exact binary64 serialization vectors in [Appendix B](https://www.rfc-editor.org/rfc/rfc8785.html#appendix-B). - **Conversion algorithm:** a pure Common Lisp implementation of **Ryu** for binary64-to-shortest-decimal conversion, using round-to-nearest, ties-to-even. Apply the RFC 8785/ECMAScript presentation rules after digit generation; do not use implementation-dependent Common Lisp printer output. - Emit lowercase `e`, the RFC/ECMAScript fixed-versus-exponent thresholds and exponent spelling, with no redundant digits or zeros. - Encode both positive and negative zero as JSON `0`. - Reject NaN and positive/negative infinity before conversion. - Canonicalization must not invoke Node, Python, an FFI helper, or an external process. ## Required implementation - [ ] Add `float` as a supported scalar base type. - [ ] Verify at initialization/test time that SBCL `double-float` has binary radix, 53-bit precision, and the IEEE-754 binary64 exponent range. - [ ] Add one canonical `float` encoder in `star-canonical-json`; route every manifest, wire-envelope, fixture, and generated-contract serialization path through it. - [ ] Implement the pure Common Lisp Ryu binary64 conversion and RFC 8785 presentation rules. - [ ] Accept only finite binary64 values; reject NaN and positive/negative infinity with structured conditions. - [ ] Canonicalize negative zero to JSON `0`. - [ ] Map Star-Lang `float` to Common Lisp `double-float`, Python `float`, and TypeScript `number`. - [ ] Keep Star-Lang `decimal` mapped to exact canonical strings. - [ ] Migrate `latitude` and `longitude` scalar bases from `decimal` to `float`. - [ ] Migrate `geo.alt` and `geo.accuracy` from `decimal` to `float`. - [ ] Add exact-output tests for every RFC 8785 Appendix B vector. - [ ] Add bit-preserving round-trip tests for finite values, including max finite, min normal, min subnormal, precision-sensitive values, and the fixed/exponent notation boundaries. - [ ] Add NaN/infinity rejection, positive/negative-zero normalization, and generated Python/TypeScript binding tests. - [ ] Add CI guards against falling back to host float printers or a second runtime. ## Research status This issue is the accepted implementation amendment for the numeric portion of `STAR-LANG-RESEARCH-009`. Synchronize that research document with this decision before marking the research ledger complete; implementation may proceed against this issue now.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nsaspy/star-lang#5
No description provided.