4 ms·
> Wrt single precision being the default floating point type in practice: The only relevant example in your list is the fact that irrational functions coerce r
by sedachv 8y ago
> Wrt single precision being the default floating point type in practice:
The only relevant example in your list is the fact that irrational functions coerce rational arguments to single floats (http://clhs.lisp.se/Body/12_acc.htm http://clhs.lisp.se/Body/12_acc.htm). Why do you think that dividing an integer by a single float should produce a double float?
- patrec 8y agoWell, at least I appear to have got half the point across so let me spell out the other half: unlike all mainstream languages (apart from Fortran, depending on your definition of mainstream) Common Lisp interprets "normal" floating point literals as single precision floats. Technically the standard does not specify this, but in practice all implementations do it this way these days. To be precise the standard says that SINGLE-FLOAT is the default, but implementing SINGLE-FLOAT as IEEE double precision float is allowable, because only a minimum precision and exponent size are suggested for each float type. CCL used to do this, using SHORT-FLOAT for IEEE single precision floats and, IIRC, both SINGLE-FLOAT and DOUBLE-FLOAT for double precision. If you don't want this (and I almost never do), you either need to explicitly specify that you want double precision, using d as an exponent marker in your literals or ensure READ-DEFAULT-FLOAT-FORMAT is bound to DOUBLE-FLOAT (not it's default SINGLE-FLOAT) when you read them (which can go wrong more easily, so the former is typically better). The coercion problem is harder to work around. So in the light of these facts what exactly is false and ridiculous about my claim that single precision floats are the default floating point type in practice in Common Lisp?
- sedachv 8y agoYou don't understand what IEEE floating point numbers are. IEEE 754 specifies a binary representation. There is no "normal" floating point literal notation. There are numbers in decimal or scientific notation, nothing about which will tell you what kind of internal representation the number should have (not even whether it should be floating point or not). You have to add syntax extensions (this is how Common Lisp does it: http://clhs.lisp.se/Body/02_cbb.htm http://clhs.lisp.se/Body/02_cbb.htm) or pick an arbitrary representation. Is setting a variable to pick a representation more troublesome or "can go wrong more easily" that setting any other kind of variable for you, or is there something special about that particular variable? You might as well complain that the default Common Lisp reader/printer does not handle C99 hex float literals.
- deleted 8y ago[deleted]
- kazinator 8y ago> You have to add syntax extensions (this is how Common Lisp does it: http://clhs.lisp.se/Body/02_cbb.htm http://clhs.lisp.se/Body/02_cbb.htm) or pick an arbitrary representation. If an unadorned numeric token such as 2.7 generates a single-precision float (32 bit IEEE 754), that is a problem. There are good justifications why the default representation should be the 64 bit double. The 32 bit single precision has too small a range and precision for general use; it is suitable mainly for saving space in large arrays. We shouldn't have to use an extra suffix to indicate that we don't want that type, but rather the common double. Even C gets this right.