#4 is_integer thinks non-numbers are sometimes integers

closed-fixed
nobody
None
5
2007-04-24
2006-11-10
Tom Breton
No

For Tinyscheme version 1.37

integer? and its underlying C function is_integer wrongly
report that some non-numerical objects are integers.

Here it consistently gives:

> (integer? ())
#t

On examining the source code, I see that is_integer makes
no test of is_number(p) and it looks like if a particular
bit is set for any member of the discriminated union,
is_integer will return TRUE.

Discussion

  • Kevin Cozens

    Kevin Cozens - 2006-11-26

    Logged In: YES
    user_id=1113465
    Originator: NO

    This is a simple thing to fix. Change the 'return' line of is_integer()from
    return ((p)->_object._number.is_fixnum);
    to
    return (type(p)==T_NUMBER && (p)->_object._number.is_fixnum);

     
  • CrusadingKNIGHT

    CrusadingKNIGHT - 2007-03-02

    Logged In: YES
    user_id=1106592
    Originator: NO

    A fix which doesn't crash would be as follows, just affecting the exposed method (this is because a lot of other functions assume is_integer can't be false unless we have a real):

    --> Line 3286:
    case OP_INTEGERP: /* integer? */
    s_retbool(is_integer(car(sc->args)));

    --> Becomes:
    case OP_INTEGERP: /* integer? */
    s_retbool(is_number(car(sc->args)) && is_integer(car(sc->args)));

     
  • Tom Breton

    Tom Breton - 2007-04-24
    • status: open --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks