What is the difference between a integer and a fixnum?
More specifically, is there an example for a number, that has different results for exact-integer? and fixnum??
What is the difference between a integer and a fixnum?
More specifically, is there an example for a number, that has different results for exact-integer? and fixnum??
Does this help:
#lang racket
(define (! n) (if (zero? n) 1 (* n (! (sub1 n)))))
(define 100! (! 100))
(fixnum? 100!)
(exact-integer? 100!)
A fixnum fits within the architecture-specific (32 or 64) bit size. An integer can be any size.
(exact-integer? 23525259203202342952593259256823482349025830975209532095702957)
(fixnum? 23525259203202342952593259256823482349025830975209532095702957)
These will return different values.
Even more specifically, the size of a fixnum depends on both the architecture and the Racket VM implementation: the maximum size will be less than (system-type 'word), as the VM will use at least one bit for tagging (and recall that one bit will be used for the sign).
On a specific system, fixnums are integers from (most-negative-fixnum) to (most-positive-fixnum), inclusive. You can get the maximum number of bits with (add1 (integer-length (most-positive-fixnum))) or (require (only-in rnrs fixnum-width)). And fixnum-for-every-system? might also be of interest.
Currently, the sizes are (where CS is the normal, recommended Racket VM implementation):
| 64 | 32> | |
|---|---|---|
| CS | 61 | 30 |
| BC | 63 | 31 |