From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 32F5A3858004 for ; Mon, 31 May 2021 20:52:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 32F5A3858004 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jjohnstn@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622494349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=sKMR9P3FHFqEyBqzWIBk6Lfwov8g7XVxNo/ooBVfnvo=; b=em1kBnOwA9YPI50ck8mzztdFY89yNpS3waTCvfioShWOyBIIhkGKUdJcc+Nj+dBUUE+NsW ECFY0/JeXVJruH0sMzceNh2KWJ5HxPDKPdz8najCDOuW73Bo/VedDcyBGLqQO4SbKxRwpB 5hb5MFMOwXyVUtFHbyJ/9VnOV7p9zVQ= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-244-5YFA0vAQOyaVinlTEW0VHg-1; Mon, 31 May 2021 16:52:27 -0400 X-MC-Unique: 5YFA0vAQOyaVinlTEW0VHg-1 Received: by mail-pj1-f69.google.com with SMTP id ot14-20020a17090b3b4eb029016677cc42f4so207408pjb.3 for ; Mon, 31 May 2021 13:52:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sKMR9P3FHFqEyBqzWIBk6Lfwov8g7XVxNo/ooBVfnvo=; b=Yfof4rI3OCA61qaABIEfMmcp4q7/cYTjjPY20cduKH2LDuJLo+vb3XN+E19QT7TwSm nDtZEcxiXM83HR6VYQIiRIvWJ0+/ZvNa+XeMUJagdpxjrF9pWURu8yWcCk7ncyskaE2x HQCPcx5jq/2HiV1bBr1yrvAgWffGUUCSOFWiSc/q2pwrQVlfbzCCp5Kqp5JxuPtFuSHN 4/wG/Xwb3ZZgw4bgZKFrJFAYqPM6KsCt85W8rVA50xq/i+su3QPb2HAPT8nqVSuAyeZg OpdR3Z+4pYLfTWmVS/PmGrbyRCtWSS04l2lg5OCWolCG+z4sXeMjF1g/lZBiq8k1M7v2 c1WQ== X-Gm-Message-State: AOAM531PsOSpTtnFeHKpM2D7AORY7zyM2U10r4Q50LWlPPq5AeMYY+LE hih+zWy7GLSVwPWy8AqsrJJBiKy2NR0yF1owf6G3JzOy3IOW4ao0vdFLUtVO8e0JR5igH0IoEKt Go0flaYyJXGTOGNXCce8h0Ni+Ssuih9o= X-Received: by 2002:a17:90a:108f:: with SMTP id c15mr8914642pja.152.1622494346531; Mon, 31 May 2021 13:52:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2sLHngDmroL/DeWeXTs9QU6yMskjfi0xvFkppgYKzYHLPlmn/P2cNVT2oimANc2a99tiiCMJi/iQcVZTPMbU= X-Received: by 2002:a17:90a:108f:: with SMTP id c15mr8914626pja.152.1622494346287; Mon, 31 May 2021 13:52:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jeff Johnston Date: Mon, 31 May 2021 16:52:15 -0400 Message-ID: Subject: Re: incorrectly rounded square root To: Paul Zimmermann Cc: Newlib Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jjohnstn@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, HTML_MESSAGE, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 May 2021 20:52:32 -0000 Hi Paul, Not all platforms supply a machine implementation of fesetround. Which platform are you using? -- Jeff J. On Tue, May 4, 2021 at 4:09 AM Paul Zimmermann wrote: > Hi, > > according to IEEE 754, the square root function should be correctly rounded > for all rounding modes. I noticed this is not the case in Newlib: > > $ cat test_sqrt.c > #include > #include > #include > > #ifdef NEWLIB > int errno; > int* __errno () { return &errno; } > #endif > > int main() > { > int rnd[4] = { FE_TONEAREST, FE_TOWARDZERO, FE_UPWARD, FE_DOWNWARD }; > char Rnd[4] = "NZUD"; > float x = 0x1.ff07fep+127f; > float y; > for (int i = 0; i < 4; i++) > { > fesetround (rnd[i]); > y = sqrtf (x); > printf ("RND%c: %a\n", Rnd[i], y); > } > } > > $ gcc -DNEWLIB -fno-builtin test_sqrt.c > /localdisk/zimmerma/newlib-4.1.0/libm.a -lm > $ ./a.out > RNDN: 0x1.ff83fp+63 > RNDZ: 0x1.ff83fp+63 > RNDU: 0x1.ff83fp+63 > RNDD: 0x1.ff83fp+63 > > The RNDZ and RNDD results are wrong. With glibc I get: > > $ gcc -fno-builtin test_sqrt.c -lm > $ ./a.out > RNDN: 0x1.ff83fp+63 > RNDZ: 0x1.ff83eep+63 > RNDU: 0x1.ff83fp+63 > RNDD: 0x1.ff83eep+63 > > Best regards, > Paul Zimmermann > >