eyeprolog 1.3.25 → 1.3.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.3.25",
6
+ "version": "1.3.26",
7
7
  "description": "EyeProlog turns facts and rules into answers and proofs.",
8
8
  "type": "module",
9
9
  "main": "./index.js",
package/src/iso.js CHANGED
@@ -6,7 +6,10 @@ import {
6
6
  properListItems, termIsGround, termToString, unify, variable, variantTerms,
7
7
  } from './term.js';
8
8
  import { sameNumberValue } from './number-value.js';
9
- import { NumberRepresentationError, createParserOperatorState, parseGoalText, parseNumberTokenText, parseTermText } from './parser.js';
9
+ import {
10
+ NumberRepresentationError, createParserOperatorState, floatRepresentationErrorFormal,
11
+ parseGoalText, parseNumberTokenText, parseTermText,
12
+ } from './parser.js';
10
13
  import { formatTermForWrite } from './write.js';
11
14
  import { emptyTerminalSequence, expandDcgBody, isListOrPartialList, validateDcgEmbeddedGoals } from './dcg.js';
12
15
  import {
@@ -1695,7 +1698,7 @@ function canonicalNumberText(value) {
1695
1698
  return value.name;
1696
1699
  }
1697
1700
  const text = numberTextFromDouble(finite);
1698
- if (text == null) throw new PrologError('representation_error(max_float)');
1701
+ if (text == null) throw new PrologError(floatRepresentationErrorFormal(value.name));
1699
1702
  return text;
1700
1703
  }
1701
1704
 
package/src/parser.js CHANGED
@@ -12,10 +12,16 @@ export class NumberRepresentationError extends Error {
12
12
  }
13
13
  }
14
14
 
15
+ export function floatRepresentationErrorFormal(text) {
16
+ return String(text ?? '').startsWith('-')
17
+ ? 'representation_error(min_float)'
18
+ : 'representation_error(max_float)';
19
+ }
20
+
15
21
  function finiteFloatTokenText(text) {
16
22
  const value = Number(text);
17
23
  if (!Number.isFinite(value)) {
18
- throw new NumberRepresentationError('representation_error(max_float)');
24
+ throw new NumberRepresentationError(floatRepresentationErrorFormal(text));
19
25
  }
20
26
  return value === 0 ? '0.0' : text;
21
27
  }
@@ -745,6 +745,7 @@ c4 ?- call((!;1)).
745
745
  input: [
746
746
  'T = 1.0e-99999, F is T.',
747
747
  'T = 1.0e99999, float(T).',
748
+ 'T = -1.0e99999, float(T).',
748
749
  'T = 1.0e99999, float(T), F is T.',
749
750
  'T = 1.0e99999, U = 2.0e99999, T > U.',
750
751
  'T = 1.0e99999, U = 2.0e99999, T < U.',
@@ -759,7 +760,12 @@ c4 ?- call((!;1)).
759
760
  assertEqual(
760
761
  (result.stdout.match(/error\(representation_error\(max_float\)\)\./g) ?? []).length,
761
762
  6,
762
- 'all overflowing literals fail while being read',
763
+ 'positive overflowing literals fail while being read',
764
+ );
765
+ assertEqual(
766
+ (result.stdout.match(/error\(representation_error\(min_float\)\)\./g) ?? []).length,
767
+ 1,
768
+ 'negative overflowing literal reports min_float',
763
769
  );
764
770
  assertEqual(result.stderr, '', 'stderr');
765
771
 
@@ -769,7 +775,14 @@ c4 ?- call((!;1)).
769
775
  } catch (error) {
770
776
  overflow = error;
771
777
  }
772
- assertEqual(overflow?.formal, 'representation_error(max_float)', 'number token overflow');
778
+ assertEqual(overflow?.formal, 'representation_error(max_float)', 'positive number token overflow');
779
+ let negativeOverflow = null;
780
+ try {
781
+ parseNumberTokenText('-1.0e99999');
782
+ } catch (error) {
783
+ negativeOverflow = error;
784
+ }
785
+ assertEqual(negativeOverflow?.formal, 'representation_error(min_float)', 'negative number token overflow');
773
786
  assertEqual(parseNumberTokenText('1.0e-99999').name, '0.0', 'number token underflow');
774
787
 
775
788
  const chars = Array.from('1.0e99999', atom);
@@ -783,7 +796,34 @@ c4 ?- call((!;1)).
783
796
  } catch (error) {
784
797
  numberCharsError = error;
785
798
  }
786
- assertEqual(numberCharsError?.formal, 'representation_error(max_float)', 'number_chars overflow');
799
+ assertEqual(numberCharsError?.formal, 'representation_error(max_float)', 'number_chars positive overflow');
800
+
801
+ const negativeChars = Array.from('-1.0e99999', atom);
802
+ let negativeNumberCharsError = null;
803
+ try {
804
+ numberChars({
805
+ goal: compound('number_chars', [variable('N'), listFromItems(negativeChars)]),
806
+ env: new Env(),
807
+ }).next();
808
+ } catch (error) {
809
+ negativeNumberCharsError = error;
810
+ }
811
+ assertEqual(negativeNumberCharsError?.formal, 'representation_error(min_float)', 'number_chars negative overflow');
812
+
813
+ let boundNegativeNumberCharsError = null;
814
+ try {
815
+ numberChars({
816
+ goal: compound('number_chars', [numberTerm('-1.0e99999'), variable('Chars')]),
817
+ env: new Env(),
818
+ }).next();
819
+ } catch (error) {
820
+ boundNegativeNumberCharsError = error;
821
+ }
822
+ assertEqual(
823
+ boundNegativeNumberCharsError?.formal,
824
+ 'representation_error(min_float)',
825
+ 'number_chars host-created negative overflow',
826
+ );
787
827
 
788
828
  let readError = null;
789
829
  try {