create3000 / titania

Titania X3D Editor
https://github.com/create3000/titania/wiki
GNU General Public License v3.0
39 stars 10 forks source link

javascript script float fields not comparable (works in x-ite) #89

Closed splace closed 5 years ago

splace commented 5 years ago
#VRML V2.0 utf8 Titania V4.5.0

Script {
    field SFFloat f 0.001
      url "javascript:
          function initialize(){
             Browser.println(f==0.001) 
        }  
      "
    }
}

// output: false
create3000 commented 5 years ago

This is because you define f as SFFloat which is internally really a float with a precision of 6-7 digits but JavaScript uses alway double precision numbers. If you access f in JavaScript the float value is converted to double which result in a number like 0.0010000000474974513 which is not 0.01 double.

create3000 commented 5 years ago

Use SFDouble values if you need to compare the values.

splace commented 5 years ago

Use SFDouble values if you need to compare the values.

this is from a broken world i found, not from me (as are virtually all my reports) their whole usefulness is to show when the browser is not behaving as older browsers did.

splace commented 5 years ago

the standard requires this to work; because it specifies ISO/IEC 19775 ECMAScript, which is without typing, what seems to be happening is that you have used a more modern version of js (with typing) in a non backwardly-compatible manor.