From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsswitch.lcs.mit.edu!newsfeed.cwix.com!skynet.be!skynet.be!ossa.telenet-ops.be!nmaster.kpnqwest.net!nreader2.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: Strange result from round References: <3227024402097431@naggum.net> Mail-Copies-To: never From: Erik Naggum Message-ID: <3227036932547256@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 33 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 05 Apr 2002 23:08:36 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader2.kpnqwest.net 1018048116 193.71.199.50 (Sat, 06 Apr 2002 01:08:36 MET DST) NNTP-Posting-Date: Sat, 06 Apr 2002 01:08:36 MET DST Xref: archiver1.google.com comp.lang.lisp:31155 * "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