Why in LISP , there is no limitation for number?

后端 未结 3 1077
野的像风
野的像风 2021-01-18 00:06

I can even calculate (expt 32768 32768) and I got:

47617047058164585203630504288757589154106580860755239912393038552191433338966834242068

3条回答
  •  鱼传尺愫
    2021-01-18 00:28

    You may find some clues by turning the question around: Why have a limitation on the size of numbers?

    There are some practical reasons for limiting the size of numbers. The representation of numbers in certain other programming languages are tied closely to the hardware architecture, with the size of numbers limited by the number of bits in the processor's registers.

    Fortunately, in Lisp, you can usually think on a more abstract level, liberating the programmer from such low level details. But such arbitrary-precision arithmetic is typically slower than limiting numbers to fit within the processor registers.

    PS: Also check out how elegantly Lisp handles fractions. Not turning fractions into floating point numbers allow precise arithmetics. For example: (+ 1/3 2/7) => 13/21

提交回复
热议问题