feat(lang): float numeric-limit accessors — examples, unit tests, docs [NL.2]
Finish NL.2 on top of the WIP compiler impl (2e9e4fe): f32/f64 expose
.min/.max plus the float-only .epsilon/.min_positive/.true_min/.inf/.nan,
folded via the shared lowerNumericLimit intercept + builder.constFloat.
- examples/0159: pins every f32/f64 accessor by untagged-union bit
reinterpret against exact IEEE-754 hex (true_min read before any
arithmetic — FTZ/DAZ), plus the defining-property checks
((1+eps)!=1 / (1+eps/2)==1, inf>max, min==-max, true_min<min_positive,
true_min>0, nan!=nan).
- examples/0160: float-only accessor on an int (s32.epsilon/u8.inf/
s64.true_min) and any accessor on a non-numeric type compile-error
cleanly (exit 1, pinned stderr).
- type_resolver.test.zig: floatLimitFor bit-pattern + property tests for
f32/f64, isLimitField coverage, null for non-float/non-limit fields.
- specs.md Numeric Limits: float accessors + the min=-max / min_positive=
smallest-normal / epsilon=ULP-of-1.0 / true_min=smallest-subnormal
clarifications, with the mandatory FTZ/DAZ flush-to-zero caveat.
readme.md overview updated.
This commit is contained in:
1
examples/expected/0159-types-float-numeric-limits.exit
Normal file
1
examples/expected/0159-types-float-numeric-limits.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
1
examples/expected/0159-types-float-numeric-limits.stderr
Normal file
1
examples/expected/0159-types-float-numeric-limits.stderr
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
19
examples/expected/0159-types-float-numeric-limits.stdout
Normal file
19
examples/expected/0159-types-float-numeric-limits.stdout
Normal file
@@ -0,0 +1,19 @@
|
||||
f64.true_min true
|
||||
f64.max true
|
||||
f64.epsilon true
|
||||
f64.min_positive true
|
||||
f64.inf true
|
||||
f32.true_min true
|
||||
f32.max true
|
||||
f32.min true
|
||||
f32.epsilon true
|
||||
f32.min_positive true
|
||||
f32.inf true
|
||||
(1+eps)!=1 true
|
||||
(1+eps/2)==1 true
|
||||
inf>max true
|
||||
min==-max true
|
||||
true_min<min_pos true
|
||||
true_min>0 true
|
||||
nan!=nan true
|
||||
typed eps bits true
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,35 @@
|
||||
error: type 's32' has no '.epsilon' — '.epsilon' applies only to float types (f32/f64); integer types expose only '.min'/'.max'
|
||||
--> examples/0160-types-float-numeric-limits-errors.sx:20:10
|
||||
|
|
||||
20 | a := s32.epsilon;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: type 'u8' has no '.inf' — '.inf' applies only to float types (f32/f64); integer types expose only '.min'/'.max'
|
||||
--> examples/0160-types-float-numeric-limits-errors.sx:21:10
|
||||
|
|
||||
21 | b := u8.inf;
|
||||
| ^^^^^^
|
||||
|
||||
error: type 's64' has no '.true_min' — '.true_min' applies only to float types (f32/f64); integer types expose only '.min'/'.max'
|
||||
--> examples/0160-types-float-numeric-limits-errors.sx:22:10
|
||||
|
|
||||
22 | c := s64.true_min;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: type 'bool' has no '.nan' — numeric limits apply only to integer and float types
|
||||
--> examples/0160-types-float-numeric-limits-errors.sx:23:10
|
||||
|
|
||||
23 | d := bool.nan;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: type 'string' has no '.max' — numeric limits apply only to integer and float types
|
||||
--> examples/0160-types-float-numeric-limits-errors.sx:24:10
|
||||
|
|
||||
24 | e := string.max;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: field 'epsilon' not found on type 'Any'
|
||||
--> examples/0160-types-float-numeric-limits-errors.sx:25:10
|
||||
|
|
||||
25 | f := MyStruct.epsilon;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
Reference in New Issue
Block a user