From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.redhat.com (mail.redhat.com [199.183.24.239]) by listman.redhat.com (Postfix) with ESMTP id 935BD2FD91 for ; Fri, 29 Sep 2000 00:09:05 -0400 (EDT) Received: (from mail@localhost) by mail.redhat.com (8.11.0/8.8.7) id e8T495H04691 for axp-list@listman.redhat.com; Fri, 29 Sep 2000 00:09:05 -0400 Received: from newton.math.purdue.edu (root@newton.math.purdue.edu [128.210.3.6]) by mail.redhat.com (8.11.0/8.8.7) with ESMTP id e8T495D04683 for ; Fri, 29 Sep 2000 00:09:05 -0400 Received: from polya.math.purdue.edu (lucier@polya.math.purdue.edu [128.210.3.194]) by newton.math.purdue.edu (8.10.1/8.10.1/PURDUE_MATH-4.0) with ESMTP id e8T493i23258 for ; Thu, 28 Sep 2000 23:09:03 -0500 (EST) Received: (from lucier@localhost) by polya.math.purdue.edu (8.9.3/8.9.3/PURDUE_MATH-3.2) id XAA20223 for axp-list@redhat.com; Thu, 28 Sep 2000 23:09:02 -0500 (EST) From: Brad Lucier Message-Id: <200009290409.XAA20223@polya.math.purdue.edu> Subject: Re: long->double->long goes negative To: axp-list@redhat.com Date: Thu, 28 Sep 2000 23:09:02 -0500 (EST) In-Reply-To: <39D3E5FA.E6BB8539@voicenet.com> from "Uncle George" at Sep 28, 2000 07:44:42 PM X-Mailer: ELM [version 2.5 PL0] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0beta4 Precedence: bulk Reply-To: axp-list@redhat.com List-Id: Linux and Red Hat on Alpha processors Well, I don't find your posting very clear, but it doesn't seem that strange to me. Perhaps I'm missing something. > main() > { > long lb,la; > double db,da; > union { long q; double d; } u; > lb =0x7fffffffffffffffL; > db = (double) lb; db has only 53 bits mantissa, so lb cannot have all its 63 bits represented exactly, and on conversion lb is rounded to the nearest number, which happens to be 9.223372036854775808e+18 > la = (long) db; Here db does have an integral value, but that value is bigger than the largest long, so it can't be represented exactly as a long; the bit pattern of the converted result is 0x8000000000000000, which doesn't seem such a bad choice in this situation. > u.d = db; > printf("lb=%ld, db=(%23.18e, %lx), la=%ld\n", lb, db,u.q, la); > } > > cc -g -mieee a.c > ./a.out