Bug in roundval?

  • Hi,

    this is my first posting to this forum. I recently started using krpano for my night-sky panorama image:

    http://galaxy.phy.cmich.edu/~axel/mwpan2/krpano/

    Two questions:

    1. While writing code to display the image center coordinates in sexagesimal notation I noticed some strange behavior in the roundval() function:

      set(Decm, 0.055); roundval(Decm,0);

      returns 1, not 0 (this seems to be the case for all values of Decm between 0.05 and 0.01). Has anyone noticed a similar behavior? I am using krpano 1.0.8.11.

    2. Is there any way of formatting text output similar to printf in C or Perl? I'd like to pad single-digit numbers with a preceding zero, i.e. what printf("%02i", ...) would do.


    Axel

  • Hi AxelM,

    That's really great *thumbup* .... I think you will have interest to this other project from Serge Brunier and Frédéric Tapissier: The heaven vault in 360°
    Link to the full page: http://sergebrunier.com/gallerie/pleinciel/index-eng.html

    About rounval()... As I know, It works exactly as you describe ... Have a look here .

    To avoid the rounding to the higher value, perhaps you could do something like this:

    Code
    set(Decm, 0.055); roundval(Decm,0);
    if(Decm GT 0.055, sub(Decm,1););

    edited: Sorry... I has thinked all the time it was 0.55 instead of 0.055 *thumbdown* so I did not notice the Bug...

    About the second question I have no idea...

    one note: you are using SPHERE as image type... I think it should be better to use CUBE instead... better general quality and rendering and the zenith/nadir without artefact.... Also, I think you should use the control.zoomtocursor feature for an improved exploration.

    Code
    <control zoomtocursor   ="true" />

    Hope this help.

    ps. 110 Messier + 1223 NGS hotspots ... *thumbsup*

    SAlut.

    Edited 3 times, last by michel (June 22, 2010 at 1:01 PM).

  • Hi,

    this is my first posting to this forum.

    Welcome!

    I recently started using krpano for my night-sky panorama image:

    http://galaxy.phy.cmich.edu/~axel/mwpan2/krpano/

    STUNNING!!!!!


    Two questions:
    [*]While writing code to display the image center coordinates in sexagesimal notation I noticed some strange behavior in the roundval() function:

    set(Decm, 0.055); roundval(Decm,0);

    returns 1, not 0 (this seems to be the case for all values of Decm between 0.05 and 0.01). Has anyone noticed a similar behavior? I am using krpano 1.0.8.11.

    Yes, this certainly appears to be a bug. In fact, roundval also fails for values such as 0.000000000055,

    Code
    set(test,0.000000000055);
    	roundval(test);
    	trace("test=",test);

    this code prints test=1.

    I guess you can use this workaround until Klaus fixes the bug (note that this does not support arbitrary precision, although it could easily be added):

    Code
    <action name="bugfix_round">
    	if (%1 GE 0,
    		add(%1,0.5);
    	<!--else-->,
    		sub(%1,0.5);
    	);
    	mod(action[%0].tmp,%1,1);
    	sub(%1,action[%0].tmp);
    	roundval(%1);
    </action>

    This code works by adding 0.5 to the value to be rounded and then truncating the value. Since there isn't a truncation function, I'm subtracting the mod 1 value from the original number. Unfortunately, because this subtraction can lead to a precision error, we call the offending roundval to ensure that the result is an integer, and roundval doesn't fail here because the error value does not contain a "000...0055" in it.


    [*]Is there any way of formatting text output similar to printf in C or Perl? I'd like to pad single-digit numbers with a preceding zero, i.e. what printf("%02i", ...) would do.
    Axel

    While this could be done by writing a relatively complex action, it seems that javascript is better suited to this problem. Here's the javascript code to add a krsprintf action:

    The sprintf function is from here. It must be referenced in your html file in a manner such as this:

    Code
    <script type="text/javascript" src="sprintf.js"></script>


    To call the function from xml, use this:

    Note that you need to use %% to "protect" the percent sign.

    Hope this helps!

    steve

  • Hi,

    thanks for the note about the rounding bug, I didn't know that,
    internally I'm only using the AS3 tofixed function and that function returns that value,
    but I have now added a workaround for the next release, then roundval(val,0); should return
    correct rounded values,

    about padding preceding zeros - I will think about an additional function for it,

    best regards,
    Klaus

  • Klaus,

    Thanks for confirming the roundval bug. I implemented Steve's krsprintf action, and it works great -- thanks, Steve!


    That's really great *thumbup* .... I think you will have interest to this other project from Serge Brunier and Frédéric Tapissier: The heaven vault in 360°


    Thanks, Michel. I know of Serge's and Frédéric's work. We finished our panoramas almost simultaneously, without being aware of each other's efforts.

    Hi AxelM,
    one note: you are using SPHERE as image type... I think it should be better to use CUBE instead... better general quality and rendering and the zenith/nadir without artefact....


    The cube version is in the making. I'll probably come up with a question or two along the way...

    Axel

  • After sleeping on it, I realized that the zeropadding function could be done pretty easily in the newest version of krpano 1.0.8.11 because it has the pow function:

    The zeropad action is called with three arguments. The first is the variable name into which the zeropadded result is returned. The second is the value to be zero padded, the third is the number of digits to which to pad.

    so

    Code
    zeropad(foo,999,6);

    sets the variable foo to the string "000999".

    just providing this as an alternative that doesn't use javascript...

    steve

Participate now!

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