Issue defining a variable as string

  • Hi Klaus,

    Most probably I'm facing a very unusual case, when I'm trying to force a variable to be a string and it seems, krpano want to resolve it as a number all the time when I use calc

    so my code is :

    Code
    def(myVar, string, 8e100682);
    debug('myVar ', myVar);
    calc(myVarCalculated, 'hello ' + myVar );
    debug('myVarCalculated ', myVarCalculated);
    Code
    DEBUG: myVarCalculated hello Infinity


    but if I use that variable it will behaves as it's a number and it shows infinity

  • Hi,

    yes, normally that should work, but there is a special behavior related to the Number-type detection here:

    Because often the intended type of an variable is not clear (e.g. Numbers are often stored as Strings) - the calc action internally 'tests' if a given value is a Number or a String to apply the correct operation. And '8e100682' is a special case here because it will be detected as 'exponential notation' because of the 'Numbers + e + Numbers' characters.
    And as 8^100682 is an incredible large value the result is 'Infinity'.

    That means normally and in the most cases the calc() action could be used also for adding/connecting strings but for strings representing numbers there could be unfortunately unexpected results...

    Best regards,
    Klaus

  • Hi,

    it has an effect for non-string types, but because string is normally/often the default type, the expression solver needs to find out if a variable might be a number. So strings were always tested if they might be numbers.

    But in version 1.19-pr11 I've improved that type checking to avoid such wrong infinity number conversion. That means with this version your example would work:
    https://krpano.com/forum/wbb/inde…72066#post72066

    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!