MantisBT - opensim
View Issue Details
0006160opensim[REGION] Script Functionspublic2012-08-15 04:082012-08-20 03:00
SignpostMarv 
 
normalmajoralways
patch feedbackopen 
master (dev code) 
 
dc82ad0
Standalone (1 Region) , Grid (1 Region per Sim)
BasicPhysics
.NET / Windows32, .NET / Windows64
None
0006160: llFloor operates on doubles rather than floats, producing differences in expected results
The repro script indicates 27 for all values in Second Life, whereas OpenSim indicates 27 for the value of a and 26 for the llFloor() results.

The attached patch changes the behaviour of llFloor() in OpenSim to match the behaviour of llFloor() in Second Life
default
{
    touch_start(integer t)
    {
        float a = 26.9999995;
        llSay(0, llList2CSV([
            a,
            llFloor(a),
            llFloor(26.9999995)
        ]));
    }
}
No tags attached.
patch llFloor-precision-problem.patch (1,129) 2012-08-15 04:08
http://opensimulator.org/mantis/file_download.php?file_id=3167&type=bug
patch llFloor-Ceil-Round-precision.patch (1,674) 2012-08-20 03:00
http://opensimulator.org/mantis/file_download.php?file_id=3229&type=bug
Issue History
2012-08-15 04:08SignpostMarvNew Issue
2012-08-15 04:08SignpostMarvFile Added: llFloor-precision-problem.patch
2012-08-15 04:08SignpostMarvStatusnew => patch included
2012-08-15 14:26justinccNote Added: 0022091
2012-08-15 14:32SignpostMarvNote Added: 0022092
2012-08-17 15:55justinccNote Added: 0022112
2012-08-17 15:56justinccNote Added: 0022113
2012-08-18 04:32DMX04Issue cloned: 0006180
2012-08-20 03:00SignpostMarvFile Added: llFloor-Ceil-Round-precision.patch
2012-08-20 03:00SignpostMarvNote Added: 0022387
2012-08-20 03:00SignpostMarvStatuspatch included => patch feedback

Notes
(0022091)
justincc   
2012-08-15 14:26   
It seems to me that this points to a more fundamental issue. If llFloor() is cast internally from double to float then llCeil(), llRound(), etc. should be as well.

But then one could ask why LSL_Float was modelled internally using a double rather than a float and save all this and future casting.
(0022092)
SignpostMarv   
2012-08-15 14:32   
26.9999995 should ceil to 27 is 26.9999995 or float-cast to 27.

I can only think llRound would have issues if it was fed a double greater than 0.5 that typecast to float would be less than 0.5
(0022112)
justincc   
2012-08-17 15:55   
No, there are other cases. For instance, in SL

default
{
    touch_start(integer t)
    {
        float a = 27.0000002;
        llSay(0, llList2CSV([
            a,
            llCeil(a),
            llCeil(27.0000002)
        ]));
    }
}

Object: 27.000000, 27, 27

but will return

Primitive: 27.000000, 28, 28

because SL casts the literals to floats with less precision than doubles. It wouldn't surprise me if there were lots of examples of this though I admit I haven't looked further.
(0022113)
justincc   
2012-08-17 15:56   
Which is why I think it would be much better to cast these straight off to floats rather than doubles if one really wants to be LSL compliant. Whether this is a good idea or not is another question.
(0022387)
SignpostMarv   
2012-08-20 03:00   
New test script:

default
{
    touch_start(integer t)
    {
        float a = 26.9999995;
        llSay(0, llList2CSV([
            a,
            llFloor(a),
            llFloor(26.9999995)
        ]));

        a = 27.0000002;
        llSay(0, llList2CSV([
            a,
            llCeil(a),
            llCeil(27.0000002)
        ]));

        a = 26.4999999;
        llSay(0, llList2CSV([
            a,
            llRound(a),
            llRound(26.4999999)
        ]));
    }
}