Flutter for Beginners
上QQ阅读APP看书,第一时间看更新

BigInt

Dart also has the BigInt type for representing arbitrary precision integers, which means that the size limit is the running computer's RAM. This type can be very useful depending on the context; however, it does not have the same performance as num types and you should consider this when deciding to use it.

JavaScript has the concept of safe integers, which Darts follows when transpiling to it. However, as JavaScript uses double-precision to represent even integers, we do not have an overflow when doing (maxInt * 2).

Now, you might consider putting BigInt everywhere you would use integers to be free of overflows, but remember, BigInt does not have the same performance as int types, making it unsuitable for all contexts.

Additionally, if you want to know how Dart VM handles numbers internally, take a look at the Further reading section at the end of this chapter.