Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what is type float-digits

47 views
Skip to first unread message

Jim Newton

unread,
Dec 5, 2016, 5:57:58 AM12/5/16
to
The CL spec defines a function FLOAT-DIGITS
http://clhs.lisp.se/Body/f_dec_fl.htm
But it doesn't define a type of that name.

SBCL does define a type of this name, which is a subtype of FIXNUM
(subtypep 'float-digits 'fixnum)
T, T

And the function FLOAT-DIGITS seems to return 24.
It does not seem to be the case that FLOAT-DIGITS is a subtype of (UNSIGNED-BYTE 24)

Can someone help me to understand what the type FLOAT-DIGITS is?

Thanks
Jim

Rob Warnock

unread,
Dec 5, 2016, 7:08:38 AM12/5/16
to
Jim Newton <jimka...@gmail.com> wrote:
+---------------
| The CL spec defines a function FLOAT-DIGITS
| http://clhs.lisp.se/Body/f_dec_fl.htm
| But it doesn't define a type of that name.
+---------------

No, but it explicitly specifies that the result
of FLOAT-DIGITS is a non-negative integer.
[Read the URL you provided again, FLOAT-DIGITS
plus the the "Arguments and Values" section.]

So I suppose the type of that result could be
specified as (AND INTEGER (NOT (SATISFIES MINUSP)))
or (INTEGER 0 *) or (UNSIGNED-BYTE), if you really
needed a concrete type for it.

+---------------
| SBCL does define a type of this name, which is a
| subtype of FIXNUM (subtypep 'float-digits 'fixnum) => T, T
+---------------

But that doesn't clearly capture the non-negative constraint.

+---------------
| And the function FLOAT-DIGITS seems to return 24.
| It does not seem to be the case that FLOAT-DIGITS
| is a subtype of (UNSIGNED-BYTE 24)
+---------------

Why would you think that? (UNSIGNED-BYTE n) specifies
the width in bits, *not* a value reange per se.

+---------------
| Can someone help me to understand what the type FLOAT-DIGITS is?
+---------------

According to the CLHS, a non-negative integer [see above].

Interestingly enough, SBCL 1.3.1's DESCRIBE function
says that the declared type of FLOAT-DIGITS's return
value is (MOD 54) [which is the same as (INTEGER 0 (54))
or (INTEGER 0 53)], but that its "derived type" is
(OR (INTEGER 24 24) (INTEGER 53 53)). Go figure...

[CMUCL's DESCRIBE also says (MOD 54).]


-Rob

-----
Rob Warnock <rp...@rpw3.org>
627 26th Avenue <http://rpw3.org/>
San Mateo, CA 94403

Didier Verna

unread,
Dec 5, 2016, 7:44:16 AM12/5/16
to
Jim Newton wrote:

> And the function FLOAT-DIGITS seems to return 24. It does not seem to
> be the case that FLOAT-DIGITS is a subtype of (UNSIGNED-BYTE 24)
>
> Can someone help me to understand what the type FLOAT-DIGITS is?

Did you notice that 24 is 42 with the digits reversed ?

--
Resistance is futile. You will be jazzimilated.

Lisp, Jazz, Aïkido: http://www.didierverna.info

Didier Verna

unread,
Dec 5, 2016, 7:46:56 AM12/5/16
to
I wrote:

> Jim Newton wrote:
>
>> And the function FLOAT-DIGITS seems to return 24. It does not seem to
>> be the case that FLOAT-DIGITS is a subtype of (UNSIGNED-BYTE 24)
>>
>> Can someone help me to understand what the type FLOAT-DIGITS is?
>
> Did you notice that 24 is 42 with the digits reversed ?

Seriously tho, I think it's related to float precision.

Jim Newton

unread,
Dec 5, 2016, 9:43:53 AM12/5/16
to
On Monday, December 5, 2016 at 1:08:38 PM UTC+1, Rob Warnock wrote:

> So I suppose the type of that result could be
> specified as (AND INTEGER (NOT (SATISFIES MINUSP)))
> or (INTEGER 0 *) or (UNSIGNED-BYTE), if you really
> needed a concrete type for it.
>

No, it is not the same as unsigned-byte, that's for sure.
(subtypep 'unsigned-byte 'float-digits)
returns NIL, T

Although it is some some subtype of unsigned-byte
(subtypep 'float-digits 'unsigned-byte)
returns T, T

Jim Newton

unread,
Dec 5, 2016, 9:48:53 AM12/5/16
to
On Monday, December 5, 2016 at 1:08:38 PM UTC+1, Rob Warnock wrote:
> No, but it explicitly specifies that the result
> of FLOAT-DIGITS is a non-negative integer.
> [Read the URL you provided again, FLOAT-DIGITS
> plus the the "Arguments and Values" section.]
>

Hi Rob, are you suggesting that the FLOAT-DIGITS type is the return type of the function of the same name?
Where do you get that idea from? I'm not saying your wrong, just I don't see why you think that.

Jim

Jim Newton

unread,
Dec 5, 2016, 9:53:59 AM12/5/16
to
I found the definition in the sbcl source code

(sb!xc:deftype float-digits ()
#!-long-float `(integer 0 ,sb!vm:double-float-digits)
#!+long-float `(integer 0 ,sb!vm:long-float-digits))

So it seems to be some fixed range of positive integers.

Raymond Wiker

unread,
Dec 5, 2016, 11:05:18 AM12/5/16
to
From the Hyperspec (that you linked to earlier):

float-digits float => digits1

and

digits1---a non-negative integer

So, float-digits returns a non-negative integer.

Further, in Lispworks 32-bit, I get

(float-digits 1.0f0) => 24

and

(float-digits 1.0d0) => 53

so, float-digits seems to return the number of bits in the mantissa of a
floating-point number (of a specific type/precision)... which is more or
less what the Hyperspec says (I think).

Rob Warnock

unread,
Dec 5, 2016, 12:20:26 PM12/5/16
to
Jim Newton <jimka...@gmail.com> wrote:
+---------------
| On Monday, December 5, 2016 at 1:08:38 PM UTC+1, Rob Warnock wrote:
| > No, but it explicitly specifies that the result
| > of FLOAT-DIGITS is a non-negative integer.
| > [Read the URL you provided again, FLOAT-DIGITS
| > plus the the "Arguments and Values" section.]
|
| Hi Rob, are you suggesting that the FLOAT-DIGITS type
| is the return type of the function of the same name?
+---------------

Exactly.

+---------------
| Where do you get that idea from? I'm not saying your wrong,
| just I don't see why you think that.
+---------------

Well, the CLHS doesn't define a type named FLOAT-DIGITS,
only a function of that name. So if the SBCL implementation
defines -- as an extension to the ANSI spec -- a type named
FLOAT-DIGITS, it seemed reasonable to me that it should match
the type of the result of the function FLOAT-DIGITS.

Kaz Kylheku

unread,
Dec 5, 2016, 2:22:51 PM12/5/16
to
Would it also seem reasonable if a type ATOM matched what
is returned by the ATOM function?

I'm not even sure that this is a conforming extension, if that
FLOAT-DIGITS symbol being defined as a type name is in fact
CL:FLOAT-DIGITS.

Rob Warnock

unread,
Dec 5, 2016, 11:40:07 PM12/5/16
to
Kaz Kylheku <221-50...@kylheku.com> wrote:
+---------------
| 2016-12-05, Rob Warnock <rp...@rpw3.org> wrote:
| > Well, the CLHS doesn't define a type named FLOAT-DIGITS,
| > only a function of that name. So if the SBCL implementation
| > defines -- as an extension to the ANSI spec -- a type named
| > FLOAT-DIGITS, it seemed reasonable to me that it should match
| > the type of the result of the function FLOAT-DIGITS.
|
| Would it also seem reasonable if a type ATOM matched what
| is returned by the ATOM function?
+---------------

You have a point. ;-}

+---------------
| I'm not even sure that this is a conforming extension, if that
| FLOAT-DIGITS symbol being defined as a type name is in fact
| CL:FLOAT-DIGITS.
+---------------

At least in SBCL 1.3.1, it is in fact CL:FLOAT-DIGITS
[see last few lines]:

* (describe 'CL:FLOAT-DIGITS)

COMMON-LISP:FLOAT-DIGITS
[symbol]

FLOAT-DIGITS names a compiled function:
Lambda-list: (F)
Declared type: (FUNCTION (FLOAT) (VALUES (MOD 54) &OPTIONAL))
Derived type: (FUNCTION (T)
(VALUES (OR (INTEGER 24 24) (INTEGER 53 53))
&OPTIONAL))
Inline proclamation: INLINE (inline expansion available)
Known attributes: foldable, unsafely-flushable, movable
Source file: SYS:SRC;CODE;FLOAT.LISP

FLOAT-DIGITS names a type-specifier:
Lambda-list: ()
Expansion: (INTEGER 0 53)
*

FWIW, SBCL also defines/exports a number of non-standard
related constant variables that seem like they should be
more useful than that questionable type specifier:

* (list SB-VM:SINGLE-FLOAT-DIGITS
SB-VM:DOUBLE-FLOAT-DIGITS
SB-VM:LONG-FLOAT-DIGITS)

(24 53 64)
*

Though those constants should be discoverable in a standard,
portable way:

* (mapcar #'float-digits (list most-positive-short-float
most-positive-single-float
most-positive-double-float
most-positive-long-float))

(24 24 53 53)

*

or, equivalently:

* (mapcar #'float-digits (list 1.0s0 1.0f0 1.0d0 1.0l0))

(24 24 53 53)
*

Unfortunately, these portable results are inconsistent
with that SB-VM:LONG-FLOAT-DIGITS symbol, leading one
to wonder which is correct. Hmmm...

* 1.0l0

1.0d0
*

Longs are actually doubles here, so the portable version is correct.
0 new messages