Sie sind nicht angemeldet.

jordi

Profi

  • »jordi« ist der Autor dieses Themas

Beiträge: 583

Wohnort: Barcelona

Beruf: creating ideas & coding them

  • Nachricht senden

1

Freitag, 14. Juli 2017, 15:09

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 :

Quellcode

1
2
3
4
def(myVar, string, 8e100682);
debug('myVar ', myVar);
calc(myVarCalculated, 'hello ' + myVar );
debug('myVarCalculated ', myVarCalculated);

Quellcode

1
DEBUG: myVarCalculated hello Infinity

but if I use that variable it will behaves as it's a number and it shows infinity
everpano.com step beyond 360

Beiträge: 770

Wohnort: Russian Federation

Beruf: Interpreting, Building virtual tours

  • Nachricht senden

2

Freitag, 14. Juli 2017, 15:59

Hi)

Txtadd gets it all right, I've just checked:

Quellcode

1
txtadd(myVarCalculated, 'hello ', get(myVar));
Regards,

Alexey

jordi

Profi

  • »jordi« ist der Autor dieses Themas

Beiträge: 583

Wohnort: Barcelona

Beruf: creating ideas & coding them

  • Nachricht senden

3

Freitag, 14. Juli 2017, 18:08

Yes, thanks for checking Alexey.

Guest I just get used too much to calc *love* ...

Even it would be nice that calc could resolve that issue...
everpano.com step beyond 360

4

Samstag, 15. Juli 2017, 23:33

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

jordi

Profi

  • »jordi« ist der Autor dieses Themas

Beiträge: 583

Wohnort: Barcelona

Beruf: creating ideas & coding them

  • Nachricht senden

5

Donnerstag, 27. Juli 2017, 13:29

So def is not having any effect on the calc action.
everpano.com step beyond 360

6

Mittwoch, 2. August 2017, 21:21

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/index.php?p…72066#post72066

Best regards,
Klaus