Skip to content

Negative Integers #1

@franksergeant

Description

@franksergeant

I received these comments via email:

I found a bug: it's not possible to enter negative integers directly, they are parsed as floats.

Example:

> -2 .
-2.0  ok
> 3 5 - .
-2  ok

Here's a simple patch, matching negative numbers by slicing up the string:

--- pygmykernel.py.0 2019-07-15 21:16:26.346736400 +0100
+++ pygmykernel.py 2019-07-18 12:48:45.259047600 +0100
@@ -294,7 +294,9 @@

     '''
     if s.isdigit():
-        # it is a decimal integer
+        # it is a positive decimal integer
+        return (True, int(s))
+    elif s[:1] == '-' and s[1:].isdigit():
       return (True, int(s))
     elif (len(s) > 1) and (s[0] == "'"):
        return (True, ord(s[1]))

This works fine for ASCII numbers in my limited testing. It will be enough for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions