Update scratch3_operators.js

Fix  and 

Take angle modulus 360 to avoid issues with floating point decimal accuracy. 
Round to 10 digits using Math.round and division instead of stringifying.
This commit is contained in:
ecc521 2019-06-09 21:19:01 -04:00 committed by GitHub
parent f74bf88ce3
commit 6ec974f710
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -136,8 +136,8 @@ class Scratch3OperatorsBlocks {
case 'floor': return Math.floor(n);
case 'ceiling': return Math.ceil(n);
case 'sqrt': return Math.sqrt(n);
case 'sin': return parseFloat(Math.sin((Math.PI * n) / 180).toFixed(10));
case 'cos': return parseFloat(Math.cos((Math.PI * n) / 180).toFixed(10));
case 'sin': return Math.round(Math.sin(n % 360 / 180 * Math.PI) * 1e10) / 1e10;
case 'cos': return Math.round(Math.cos(n % 360 / 180 * Math.PI) * 1e10) / 1e10;
case 'tan': return MathUtil.tan(n);
case 'asin': return (Math.asin(n) * 180) / Math.PI;
case 'acos': return (Math.acos(n) * 180) / Math.PI;