简体   繁体   English

Javascript 整数与浮点 memory - 小数位数是否会影响 memory?

[英]Javascript Integers vs Floating Point memory - do number of decimal places affect memory?

Have some svg files with many points, running lots of calculations on these values...trying to optimize calculations and memory:有一些包含许多点的 svg 文件,对这些值进行大量计算...尝试优化计算和 memory:

Floating Point values store twice as much memory as integers:浮点值存储的 memory 是整数的两倍:

// 5 is less memory than 5.6789

What about within Floating Point values - do fewer decimal places require less memory?在浮点值内怎么样 - 小数位数越少需要更少的 memory?

// Does 5.12 require less memory than 5.12341234647839234798372938719 ? // Does 5.12 require less memory than 5.12341234647839234798372938719

EDIT: removed PI and replaced with generic random number.编辑:删除 PI 并替换为通用随机数。

The Number type is double-precision 64-bit IEEE 754 binary floating point. Number类型是双精度 64 位 IEEE 754 二进制浮点数。 All values (from 5 to 5.12341234647839234798372938719) occupy the same amount of memory (eight raw bytes of memory, with possible overhead from object wrapping, depending on engine), but precision is limited; All values (from 5 to 5.12341234647839234798372938719) occupy the same amount of memory (eight raw bytes of memory, with possible overhead from object wrapping, depending on engine), but precision is limited; the literal 5.12341234647839234798372938719 is expressing false precision (eg 5.12341234647839234798372938718 is the same value).文字5.12341234647839234798372938719表示错误的精度(例如5.12341234647839234798372938718是相同的值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM