[Openmcl-devel] Type-of and positive/negative integers

Stas Boukarev stassats at gmail.com
Thu Oct 24 04:25:29 PDT 2019


"1. For any object that is an element of some built-in type:"

3 is an element UNSIGNED-BYTE

"a. the type returned is a recognizable subtype of that built-in type."
(subtypep '(integer 0 4611686018427387903) 'unsigned-byte) => T
while
(subtypep 'fixnum 'unsigned-byte) => NIL

-3 is not an element of UNSIGNED-BYTE, but of SIGNED-BYTE,
and
(subtypep 'fixnum 'signed-byte) => T

On Thu, Oct 24, 2019 at 9:30 AM Steven Nunez <steve_nunez at yahoo.com> wrote:
>
> I've been stumped by trying to understand why:
>
> ? (type-of -3)
> FIXNUM
> ? (type-of 3)
> (INTEGER 0 1152921504606846975)
> ?
>
> return different types. I know that type-of is somewhat ill-defined, but in my reading of the spec, '3' should also be a fixnum, since it is between most-negative-fixnum and most-positive-fixnum. CLtL2 suggests that implementors return the most specific type, and that would also be fixnum. Steele later points out some flaws in the current specification of type-of. Both CCL and SBCL exhibit this behaviour.
>
> Two questions for the smart ones out there:
>
> Is there something in the spec that I missed that makes type-of behave this way?
> Is there a way to do a type checking assertion for fixnums that works with both positive and negative integers? I am trying to optimize some numerical functions.
>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> https://lists.clozure.com/mailman/listinfo/openmcl-devel



More information about the Openmcl-devel mailing list