You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, September 25th 2019, 8:51am

inline function bug?

Hi,

Trying to use the new inline functions but they seem to be buggy.

This returns -75.00
calc(FOVnow,roundval(view.fov,2));
calc(var.Result,0 - FOVnow);

This Returns 075.00
calc(var.Result,0+roundval(view.fov,2));

This Returns NaN
calc(var.Result,0 - roundval(view.fov,2));

2

Wednesday, September 25th 2019, 10:00am

this is a type problem --> 0 <number> + "75.00" <string> = "075.00" <string>

calc(var.Result,0+1*roundval(view.fov,2)); // would work in js but not in xml code
calc(var.Result,0+number(roundval(view.fov,2))); // this works

but strange that roundval returns a string ! ... *confused*

3

Wednesday, September 25th 2019, 3:11pm

Hi,

it's correct/intended to work that way - roundval() returns a String.

Otherwise it wouldn't be possible to store the rounded value correctly.

Best regards,
Klaus

4

Thursday, September 26th 2019, 3:27pm

That makes sense. I wouldn't have guessed the result would be a string.
Very useful function in the end. The amount of times I'm creating a variable just so it can be rounded. Now I can just round it within the calc function. Woohoo.

I guess I've often wondered if roundval actually speeds anything up. I do it because the original values have 10 or so decimal places so I thought the calculations were creating really long numbers which would slow things down. Maybe the rondval is even slower than just working with the decimals.

5

Wednesday, October 2nd 2019, 2:00pm

so I thought the calculations were creating really long numbers which would slow things down.
No, that doesn't matter at all.
Internally the computer works with the Numbers in floating-point format.
A long number is only the result from the conversion to a display-able text.

Maybe the rondval is even slower than just working with the decimals.
Yes, when using roundval during calculations it makes them slower. In this case the Number need to be converted to a string with given decimal-points and then for the next calculation again converted back to a Number.