From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Panicz Maciej Godek Newsgroups: gmane.lisp.guile.user Subject: Double-precision floating point arithmetics behaves differently in Guile and in C Date: Sun, 26 Sep 2021 10:45:51 +0200 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31489"; mail-complaints-to="usenet@ciao.gmane.io" To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 26 10:54:32 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mUPvc-00081G-4O for guile-user@m.gmane-mx.org; Sun, 26 Sep 2021 10:54:32 +0200 Original-Received: from localhost ([::1]:56136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUPvb-0003nz-3o for guile-user@m.gmane-mx.org; Sun, 26 Sep 2021 04:54:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUPnU-0006Ay-PI for guile-user@gnu.org; Sun, 26 Sep 2021 04:46:08 -0400 Original-Received: from mail-io1-xd30.google.com ([2607:f8b0:4864:20::d30]:33430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUPnR-0002TV-3u for guile-user@gnu.org; Sun, 26 Sep 2021 04:46:08 -0400 Original-Received: by mail-io1-xd30.google.com with SMTP id n71so18677726iod.0 for ; Sun, 26 Sep 2021 01:46:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:from:date:message-id:subject:to; bh=lH2SpyLBm2izEuDEij5oZcEK6e88B/nvhXlaFjUdb0s=; b=BIBFaDSsjbMoW/RoGNiyXQVB4rTQzAm7s+enik145Z2lOJbrMstjr+3z6zqrEWhMT2 mnKkr5ibTzD87SWrQKyXWmqDkHyPr0PearT3ubBotPRR/wulyNJSkKdeskw8bvOLuxr1 TPl+7Y3VFStCB4Lz/4Mu2yTEu1/2YKT0eEhjWt++rb6HTHeZ+5zWQXloWl5njO8A2KDI mXR3ug7EuhChslvNvt3XVgb7ZoVDZH0bJVT4cPvwCsDYpxad+fycuDbLvamxq1YeU6UN qsI7r4H1Gmf+cwAO4i/LN2E3kZ/Et//dx0tn9EMGqKjPuYVUsrOt9Xpsp20nPEy961G0 73KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=lH2SpyLBm2izEuDEij5oZcEK6e88B/nvhXlaFjUdb0s=; b=DCttruEd5jwIQYHODt59A32nwl8eB8+mZbJ85CAmjsVF8tnANF9UUivJttCQoaN6pW crUKZgdszL/50K3JpuIvd23+5u2g7cLsSnbRyTjLI4cF+U7LbvEYusWbYUKgYkzBhz81 MWcIVHv9ztPo4dxCxW76DuqKbfTlWdWgSjR20ybJWW1RMb8mZiGH278TI5y/oYOwx8si Q7l0dKk9WK8PGIDfxySLOL6OHyBOlhTVxh+BJiglWWjRaJCtykxYcPeJhTHJGk6ARGKs SraV2Qjbb8ACvtY1NeYA+NrU7UPoaxzzKMOd8jLJoij3vA5w0TWDODRPinvwx+L5YVtn OR+Q== X-Gm-Message-State: AOAM531xDPCcMjWVji7K7aiBzKPqo0Hmy42TwOjUT+vUMD4p8jhZcbr4 GyQ/ES1pu1W3FBteRCRwAWxxnw0b9i3/SQllb2XfjnXhs76iKw== X-Google-Smtp-Source: ABdhPJwMhOVNxTgznU0953ECQpIJDDHdaEkTYzBJk3rdRfCGP2dy4LO9+dg7v7huWEfwIbJU1X1DA0n4sX1WVc9IPiA= X-Received: by 2002:a05:6638:22d1:: with SMTP id j17mr16687613jat.129.1632645962167; Sun, 26 Sep 2021 01:46:02 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::d30; envelope-from=godek.maciek@gmail.com; helo=mail-io1-xd30.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URI_DOTEDU=1.997 autolearn=no autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17779 Archived-At: Hi, I recently ran into a very weird problem. I am using code for computing Singular Value Decomposition that's been ported do Scheme by Gerald Sussman as a part of the scmutils package (more specifically, I use some bits of code extracted from guile-scmutils ) The code is too long to paste here, but I have uploaded a copy to my github . I have found an ellipsoid-fitting algorithm that leans on this SVD code: when I run it on a randomly generated set of points lying on an ellipsoid, the ellipsoid parameters are reconstructed correctly. The trouble begins when I try to port that code to C. Initially, I have used a C code for computing SVD that I've found elsewhere (which was based on the same Fortran code from LINPACK), but I eventually wrote code to convert Scheme code to C to make sure that both algorithms are identical (and at this point I am quite confident that they are). The problem is, that the results of floating-point operations behave slightly differently in C than in Guile, and these small numerical differences accumulate, and eventually start making huge differences -- at least that's something that I've noticed. Moreover, I can quite confidently say that the results that I get in C are incorrect -- that the *eigenvalues* (which translate to the radii of the ellipsoid) are very different, the calculated center of the ellipsoid is slightly different, and that the *eigenvectors* (which can be interpreted as a rotation of the ellipsoid) are very similar. Either way, the ellipsoid isn't reconstructed correctly, because the points used for reconstruction do not lie near that ellipsoid (unlike in the case of the C code). I am really troubled with this behavior -- according to the documentation, and to the bits of source code that I managed to analyze, Guile uses exactly the same representation of floating point numbers as the one I use in C -- namely, the double type. (I only use single-precision floats to express the input points, but I ran some tests using small integers on inputs, to make sure, that they are exactly representable -- and the results were still very different) Is there a way to make sure that the floating point operations in C behave identically as those in Guile?