Repository navigation
Commit ffd628b
authored
fix: Keep the trailing zeros of a floatstring range element (#345)
* fix: Keep the trailing zeros of a floatstring range element
Review on #342 pointed out that the string form of a <FloatRangeList> element
exists in order to carry the scale it was written with: a range element written
'2.50' is asking for `2.50` on a command line, and a renderer handed `2.5`
instead has been given a different string. It is also the only way a template
can ask for a fixed number of decimal places, because a <float> literal of 2.50
is the same literal as 2.5 once parsed. #342 normalized the element to the number
it denotes and threw that away.
Split the two kinds of zero, which are not the same thing:
- Leading zeros are not part of the number and still go. '02' on an INT range
is the task value 2, and forwarding the text renders `--frame 02`.
- Trailing zeros are the author's chosen scale and are kept. '02.50' renders
`2.50`, not `2.5`.
The already-landed conformance fixture EXPR/jobs/expr1.3.4--float-passthrough
pins the same rule for a FLOAT parameter default, so both it and
base/jobs/3.4.1.2 can now be right at once. openjd-specifications#180 states the
rule as Template Schemas §7.5.
A <floatstring> therefore renders as its own text less any redundant leading
zeros, which is a substring operation rather than a numeric one. That is what
removes the machinery the two preceding commits added, because every problem
they were solving came from having to choose a notation in which to re-render a
Decimal:
- normalize() and quantize() round to getcontext().prec, so an embedding
application's decimal context changed what this library rendered: measured,
'1.2345678901234567890123456789012345678901' came back as '1.2346' under
getcontext().prec = 5.
- str(Decimal) switches to exponent notation once the adjusted exponent falls
below -6, so '0.0000001' rendered 1E-7.
- format(value, 'f') is exact and plain at every magnitude but unbounded in the
exponent, so '1e999999999' -- 11 characters of template text -- expanded to
~10**9 characters and needed a length bound to stay safe.
Text needs none of those decisions. '1e999999999' now costs its own 11
characters, so the exponent bound and its boundary cases are gone with it, and an
element can no longer silently exceed TaskParameterStringValueAsJob's
1024-character cap and fall through to a numeric member of the union.
An <intstring> is unaffected: int() already discards leading zeros and there are
no fractional digits to preserve.
Verification. Model suite 5527 -> 5529 passed, 24 skipped, 3 xfailed; ruff, black
and mypy clean at the CI-pinned versions. Three mutants confirm the tests pin
both halves of the rule: dropping the leading-zero strip fails 7 tests,
restoring the trailing-zero strip fails 7, and dropping the int() conversion
fails 3.
Full 2023-09 conformance suite, run from source against openjd-cli mainline
7c7ece4 with openjd-sessions 0.10.14, on openjd-specifications#180's tree: 1162
passed, 0 failed. The baseline at e7a17b3 passes 1161 and fails only
base/jobs/7.5--numeric-string-zeros-in-range-elements, so this closes that one
fixture and moves nothing else. Both controls hold --
base/jobs/3.4--float-parameter and EXPR/jobs/expr1.3.4--float-passthrough.
Relative to released 0.11.6 the only behaviour change here is the leading-zero
trim: every element whose rendering differs from 0.11.6 differs by a removed
leading zero.
openjd-rs, which backs this package's `openjd.model._v1` API, needs the matching
change; that is OpenJobDescription/openjd-rs#354. With both in place the two
implementations render every range-element case tested identically, including
the zero and exponent forms.
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
* fix: trim a floatstring range element and unsign a zero
Two review findings, both cases where the forwarded text did not match what
openjd-rs renders for the same element.
float() ignores surrounding whitespace but the regex does not, so ' 1.5 ' was
forwarded with its spaces and reached a command line as --frame ' 1.5 '.
openjd-rs trims the resolved element before keeping it; do the same here.
Zero has no sign. '-0.0' rendered -0.0 here and 0.0 on mainline and in openjd-rs,
which is the reading the deleted test pinned by name. Drop the sign without
dropping the decimal places, so '-0.00' renders 0.00. Text that reaches zero only
by underflow, like '1e-400', does not render the value and is not kept -- which
also covers the huge negative exponents, since '1e-999999999' underflows to zero.
Both now agree with openjd-rs#354 on every case measured: ' 1.5 '->1.5,
'-0.0'->0.0, '-0.00'->0.00, '1e-400'->0.0, '5.'->5., '.5'->.5, '+2.50'->+2.50,
'1E+2'->1E+2.
Also soften a test comment that claimed an element can no longer exceed
TaskParameterStringValueAsJob's cap and fall through to a numeric member of the
union. That holds for the huge-exponent inputs the test parametrizes, but long
literal text still can, on this branch and on mainline and 0.11.6 alike -- only
the expansion is gone.
Verification. Model suite 5533 passed, 24 skipped, 3 xfailed; ruff, black and
mypy clean. Full 2023-09 conformance 1162 passed, 0 failed.
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
* fix: decide a zero spelling from the text, not the parse
Review found that testing `value == 0.0` discarded the digits of any value too
small for a float. '0.' followed by 400 zeros and a 1 -- plain decimal text,
exactly what a <floatstring> is for -- underflowed and rendered 0.0, silently a
different number. The cutoff was an artifact of binary64 rather than anything in
the template: 1e-320 is subnormal and survived, 1e-400 did not.
Ask the text instead. An all-zero mantissa spells zero whatever the exponent, so
'0.00', '-0.0' and '0e5' lose their sign and keep their digits, while '1e-400'
and '0.000...1' keep both. Mirrors openjd_expr::value::text_spells_zero, so
openjd-rs#354 renders every one of these identically.
Verification. Model suite 5536 passed, 24 skipped, 3 xfailed; ruff, black and
mypy clean. Full 2023-09 conformance 1162 passed, 0 failed.
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
---------
Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>1 parent 262d3d2 commit ffd628b
3 files changed
Lines changed: 105 additions & 154 deletions
File tree
- src/openjd/model/v2023_09
- test/openjd/model_v0
- v2023_09
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1258 | 1258 | | |
1259 | 1259 | | |
1260 | 1260 | | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
1261 | 1274 | | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
1267 | 1281 | | |
1268 | 1282 | | |
1269 | | - | |
1270 | | - | |
1271 | | - | |
1272 | | - | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | | - | |
1282 | | - | |
1283 | | - | |
1284 | | - | |
1285 | | - | |
1286 | | - | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
1302 | | - | |
1303 | | - | |
1304 | | - | |
1305 | | - | |
1306 | | - | |
1307 | | - | |
1308 | | - | |
1309 | | - | |
1310 | | - | |
1311 | | - | |
1312 | | - | |
1313 | | - | |
1314 | | - | |
1315 | | - | |
1316 | | - | |
1317 | | - | |
1318 | | - | |
1319 | | - | |
1320 | | - | |
1321 | | - | |
1322 | | - | |
1323 | | - | |
1324 | | - | |
1325 | | - | |
1326 | | - | |
1327 | | - | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
1328 | 1290 | | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
1329 | 1299 | | |
1330 | 1300 | | |
1331 | 1301 | | |
| |||
1340 | 1310 | | |
1341 | 1311 | | |
1342 | 1312 | | |
1343 | | - | |
1344 | | - | |
1345 | | - | |
1346 | | - | |
1347 | | - | |
1348 | | - | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
1354 | 1317 | | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
1359 | 1321 | | |
1360 | 1322 | | |
1361 | 1323 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
613 | 613 | | |
614 | 614 | | |
615 | 615 | | |
616 | | - | |
617 | | - | |
| 616 | + | |
| 617 | + | |
618 | 618 | | |
619 | 619 | | |
620 | 620 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
441 | 441 | | |
442 | 442 | | |
443 | 443 | | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
451 | 450 | | |
452 | 451 | | |
453 | 452 | | |
| |||
471 | 470 | | |
472 | 471 | | |
473 | 472 | | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
483 | 486 | | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
484 | 490 | | |
485 | | - | |
486 | | - | |
487 | | - | |
488 | | - | |
489 | | - | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
500 | 507 | | |
501 | 508 | | |
502 | 509 | | |
503 | | - | |
| 510 | + | |
504 | 511 | | |
505 | 512 | | |
506 | 513 | | |
507 | | - | |
| 514 | + | |
508 | 515 | | |
509 | 516 | | |
510 | 517 | | |
511 | 518 | | |
512 | 519 | | |
513 | | - | |
| 520 | + | |
514 | 521 | | |
515 | 522 | | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | 523 | | |
544 | 524 | | |
545 | 525 | | |
546 | | - | |
547 | | - | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
548 | 534 | | |
549 | 535 | | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
556 | 541 | | |
557 | 542 | | |
558 | 543 | | |
559 | 544 | | |
560 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
561 | 550 | | |
562 | 551 | | |
563 | | - | |
| 552 | + | |
564 | 553 | | |
565 | 554 | | |
566 | 555 | | |
| |||
573 | 562 | | |
574 | 563 | | |
575 | 564 | | |
576 | | - | |
577 | | - | |
| 565 | + | |
| 566 | + | |
578 | 567 | | |
579 | 568 | | |
580 | 569 | | |
| |||
0 commit comments