Question: Minimum value of integer lisp

Question

Minimum value of integer lisp

Answers 2
Added at 2016-12-19 13:12
Tags
Question

I am tryin to retrieve the minimum value of integer in lisp. I found

most-negative-fixnum 

variable that should represent the lowest possible number. whatever i try doing with it is throws error

Variable `MOST-NEGATIVE-FIXNUM' is unbound.

Is there any specific way how to get the value of variables in lisp? My research about this is without results.

Thanks

Answers to

Minimum value of integer lisp

nr: #1 dodano: 2016-12-19 13:12

It should work as follows, using for example SBCL as an implementation of Common Lisp:

CL-USER> (lisp-implementation-type)
"SBCL"
CL-USER> (lisp-implementation-version)
"1.3.12.51-868cff4"
CL-USER> most-negative-fixnum
-4611686018427387904

[...] variable that should represent the lowest possible number

That would be the lowest possible fixnum. You have big numbers too:

CL-USER> (* 10000 most-negative-fixnum)
-46116860184273879040000
nr: #2 dodano: 2016-12-19 15:12

Since Common Lisp has bignum as a part of its specifications there are no limit to how low numeric value you can have from the language point of view.

Since machines have finite memory you will experience that there is a limit to how low the numbers your machine can have. It's not possible for an implementation to know this number or show it to you without actually trying to make it or perhaps the implementation has some ideas of th eoverhead. Without overhead you can use your available memory in bytes as an estimate and you'll have 8 bits per available byte. Eg my machine has about 11GB available so I guess I can use 10GB as the actual storage and sign, ie. 80G bits for the actual number. -2^80G+1 or ~-10^2900000000. You won't be able to print it since you have no available memory.

Source Show
◀ Wstecz