Darlyn
Darlyn

Reputation: 4938

Minimum value of integer lisp

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

Upvotes: 1

Views: 1446

Answers (2)

Sylwester
Sylwester

Reputation: 48745

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.

Upvotes: 2

coredump
coredump

Reputation: 38809

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

Upvotes: 6

Related Questions