Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006104opensim[REGION] Script Functionspublic2012-07-24 04:272012-08-02 19:04
Assigned To 
PlatformOperating SystemOperating System Version
Product Versionmaster (dev code) 
Target VersionFixed in Version 
Summary0006104: vector math precision
DescriptionIf one performs certain math operations on a vector and then perform an equality check on that vector with another vector, one will get FALSE.
Steps To ReproduceUse a script with similar arguments:

float scaleMultiplier = 1.5;
list supportedSizes = [
    <.440, .140, .215>

Set a prim's size to be a vector multiplied by the scaleMultiplier.

Get the prim's new size then:

vector foo = primNewSize / scaleMultiplier;

integer j;
integer k=llGetListLength(supportedSizes);
integer valid = FALSE;
vector current;
    current = llList2Vector(supportedSizes,j);
    if(curren == foo){
        valid = TRUE;

after exiting the loop, valid will be FALSE.

In order for valid to equate to TRUE, one needs to do this before entering the loop:

foo *= 1000000;
foo.x = llRound(foo.x);
foo.y = llRound(foo.y);
foo.z = llRound(foo.z);
foo /= 1000000;
TagsNo tags attached.
Git Revision or version number892dd59b131
Run ModeStandalone (1 Region)
Physics EngineBasicPhysics
Script Engine
Environment.NET / Windows32
Mono VersionNone
Attached Files

- Relationships

-  Notes
kcozens (administrator)
2012-08-02 19:04

Comparing floats for equality is never a good idea. You assign a variable a given float value but you don't know for certain how accurately that value is internally. If you want to do some tests on this I would suggest you print out the original vector, the one multiplied by the constant, and the one that was multiplied and then divided. That will let you see where you are running into limits in the accuracy of floating point numbers in the computer.

- Issue History
Date Modified Username Field Change
2012-07-24 04:27 SignpostMarv New Issue
2012-08-02 19:04 kcozens Note Added: 0021971

Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker