Subject: Re: Strange result from round
From: Erik Naggum <erik@naggum.net>
Date: Fri, 05 Apr 2002 23:08:36 GMT
Newsgroups: comp.lang.lisp
Message-ID: <3227036932547256@naggum.net>

* "Geoff Summerhayes"
| I threw this together today after not finding anything to print out a
| float in a base other than decimal.  It's more for exploration of
| floating point in different bases than anything else. I was aiming to
| write something that produced something more along the lines of
| -1.110110*10^1010 without really ramping up the error in the
| representation, perhaps over the weekend.
| 
| (defun print-float-base(float &optional (base 10) (stream *standard-output*))
|   (let ((*print-base* base)
|         (*print-radix* t))
|     (multiple-value-bind (signif expon sign)
|         (integer-decode-float float)
|       (format stream "~&#.(* ~A (float ~A) (expt ~A ~A))~%"
|               sign signif (float-radix float) expon))))

  scale-float is a more efficient way of changing the exponent.  Also
  remember to use a (unit) float of the same type as the argument float for
  the float call, or you end up just playing with single-floats.  Quoted
  from the standard on the integer-decode-float page:

(multiple-value-bind (signif expon sign)
                     (integer-decode-float f)
  (scale-float (float signif f) expon)) ==  (abs f)

  I tend to use the function rational to decode floating point numbers.

///
-- 
  In a fight against something, the fight has value, victory has none.
  In a fight for something, the fight is a loss, victory merely relief.

  Post with compassion: http://home.chello.no/~xyzzy/kitten.jpg