Menu

VAL function issue

Anonymous
2014-08-15
2014-08-26
  • Anonymous

    Anonymous - 2014-08-15

    The VAL function is returning zero if the string has leading white space.

    Test program:
    10 print val(str$(5.5))

    This prints the value 0 (zero).

    One possible fix that seems to work is in the function "str_to_value_keep" in file "representation.py":

    def str_to_value_keep(strval, allow_nonnum=True):
        if strval==('$',''):
            return vartypes.null['%']
        strval = vartypes.pass_string_unpack(strval)
        # WJB - Remove leading (and trailing) white space from string.
        if ( allow_nonnum ):
            strval = strval.strip ()
        ins = StringIO(strval)
        outs = StringIO()
        tokenise_number(ins, outs)    
        outs.seek(0)
        value = util.parse_value(outs)
        if not allow_nonnum:
            if util.skip_white(ins) != '':
                # not everything has been parsed - error
                return None    
        return value
    

    However I don't know the parser well enough to know whether that creates any other issues.

    Regards,

    WJB

     
  • Rob Hagemans

    Rob Hagemans - 2014-08-17

    Thanks for the report, I've confirmed the bug in the development branch and am checking how to fix this without breaking other things.

    Unfortunately representation.py is one of the oldest parts, and probably the worst part, of the code (as you will have noticed when looking for a solution). In fact I'm pretty sure this bug is a regression caused by another bug I fixed earlier and the general appallingness of that bit of the code :)

     
  • Rob Hagemans

    Rob Hagemans - 2014-08-17

    Fixed now in master and development branches. Thanks again for your bug report & patch.

    Rob

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.