Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006099opensim[REGION] Scripting Enginepublic2012-07-18 12:342014-06-20 17:05
Reporterargus Portal 
Assigned To 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0006099: llSin and llCos: float to integer works wrong
Description// issue-describing: if i assign the result (here -1) of llSin to the float-variable dummyf,
// so the result get lost, when i assign it via casting to the integer-variable
// dummyi.
// But: if i assign the -1 directly to dummyf, then the casting works well and the
// -1 survive.
// Whatever i try: The value only survive, if i assign it directly (like a constant)
// The Workaround that i found: convert the float-value in a string-value. Then convert it
// back to integer: The value survive.
float dummyf;
integer dummyi;
integer integerfloat_bug_repair(float f)
   string dummy_fs;
   dummy_fs = (string)f;
   return (integer)dummy_fs;
    touch_start(integer nr)
        llSay(0,"direct: " + (string)llSin(270*DEG_TO_RAD));
        dummyi = (integer)llSin(270*DEG_TO_RAD);
        llSay(0,"dummyi - BUG: shows 0 instead of -1: " + (string)dummyi);
        dummyf= -1.0;
        dummyi = (integer) dummyf;
        llSay(0,"dummyi - shows correct value by direct-assign: " + (string)dummyi);
        dummyi = integerfloat_bug_repair(llSin(270*DEG_TO_RAD));
        llSay(0,"dummyi - shows correct value after workaround: " + (string)dummyi);

Steps To Reproducejust run the script above
TagsNo tags attached.
Git Revision or version number1926de5a0599051c27c065fb06da3dc536e6784a
Run Mode Grid (Multiple Regions per Sim)
Physics EngineBasicPhysics
Script Engine
Environment.NET / Windows32
Mono VersionNone
Viewerall Viewers
Attached Files

- Relationships

-  Notes
argus Portal (reporter)
2014-06-20 16:03

Addition: When I replace llSin with an dummy-function, that only returns -1.0
then it works.

So : Affected is llSin and llCos. Therefore I change the Title of that Mantis.
dahlia (administrator)
2014-06-20 16:28

        float fValue = 0.9999999999999;
        float iValue = (integer) fValue;
        llSay(0, "fValue:" + (string) fValue + " iValue:" + (string) iValue);

        fValue = -0.9999999999999;
        iValue = (integer) fValue;
        llSay(0, "fValue:" + (string) fValue + " iValue:" + (string) iValue);

[16:25] Primitive: fValue:1.000000 iValue:0.000000
[16:25] Primitive: fValue:-1.000000 iValue:0.000000

Looks like the cast to string is rounding but the cast to integer is not. I suspect due to floating point precision issues it may be nearly impossible to get exactly 1.0 or -1.0 from llSin() or llCos(), so your conversion to integer will likely always have a value of 0.
argus Portal (reporter)
2014-06-20 16:36

My Script works in SecondLife and in Inworldz.

This bug appear in Osgrid, Metropolis and in Avination.
dahlia (administrator)
2014-06-20 16:42

If a cast to integer is rounding in SL or InWorldz, I'd call that a bug as it should only truncate the fractional part. If it's due to some other effect, it *may* be a bug, however, using a cast to integer of the output of llSin or llCos is probably not a good practice as there is much uncertainty around floating point precision.
argus Portal (reporter)
2014-06-20 16:56

Sure. But I had a reason for the casting. (Can't remember at the moment, because its an old project). If i have to cast, I can work with an intermediate-value. This is not a problem. I was pretty sure, that this is a bug. What you are saying now let me doubt that. So this Mantis is "solved" ?
dahlia (administrator)
2014-06-20 17:05

Solved? Well possibly explained. There may be room for improvement in our implementation of llSin or llCos but I'd be surprised if many scripts fail because of such. Probably wouldn't hurt to leave it open for a bit and see if others chime in :)

- Issue History
Date Modified Username Field Change
2012-07-18 12:34 argus Portal New Issue
2014-06-20 16:03 argus Portal Note Added: 0026318
2014-06-20 16:03 argus Portal Summary float to integer works wrong => llSin and llCos: float to integer works wrong
2014-06-20 16:28 dahlia Note Added: 0026319
2014-06-20 16:36 argus Portal Note Added: 0026320
2014-06-20 16:42 dahlia Note Added: 0026321
2014-06-20 16:56 argus Portal Note Added: 0026322
2014-06-20 17:05 dahlia Note Added: 0026323

Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker