public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/27121] New: precision error on M_2_SQRTPI
@ 2020-12-28 11:11 agepap at yahoo dot com
  2020-12-28 14:37 ` [Bug math/27121] " adhemerval.zanella at linaro dot org
  2020-12-28 17:42 ` agepap at yahoo dot com
  0 siblings, 2 replies; 3+ messages in thread
From: agepap at yahoo dot com @ 2020-12-28 11:11 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27121

            Bug ID: 27121
           Summary: precision error on M_2_SQRTPI
           Product: glibc
           Version: 2.32
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: math
          Assignee: unassigned at sourceware dot org
          Reporter: agepap at yahoo dot com
  Target Milestone: ---

Created attachment 13081
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13081&action=edit
mathematical constants with 128 decimal digits

when i realized that python can do integer calculations with any precision, I
wrote a quick small program to calculate the math constants with enough
precision.
The results agree with the constants f128 in math.h except the 
M_2_SQRTPI=1.128379167095512573896158903121545172
the calculation gave the result
M_2_SQRTPI=1.128379167095512549034033270026823138

I attached the python3 program witch giving the output
      
ln2=0.69314718055994530941723212145817656807550013436025525412068000949339362196969471560586332699641868754200148102057068573368552023
      
ln3=1.09861228866810969139524523692252570464749055782274945173469433363749429321860896687361575481373208878797002906595786574236800422
      
ln5=1.60943791243410037460075933322618763952560135426851772191264789147417898770765776463013387809317961079996630302171556289972400522
      
ln7=1.94591014905531330510535274344317972963708472958186118845939014993757986275206926778765849858787152699306169420585114091172375225
     
ln10=2.30258509299404568401799145468436420760110148862877297603332790096757260967735248023599720508959829834196778404228624863340952546
       
pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460
        
e=2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200305992181741359
  
log2(e)=1.44269504088896340735992468100189213742664595415298593413544940693110921918118507988552662289350634449699751830965254425559310168
 
log10(e)=0.43429448190325182765112891891660508229439700580366656611445378316586464920887077472922494933843174831870610674476630373364167928
     
pi/2=1.57079632679489661923132169163975144209858469968755291048747229615390820314310449931401741267105853399107404325664115332354692230
     
pi/4=0.78539816339744830961566084581987572104929234984377645524373614807695410157155224965700870633552926699553702162832057666177346115
     
1/pi=0.31830988618379067153776752674502872406891929148091289749533468811779359526845307018022760553250617191214568545351591607378582369
     
2/pi=0.63661977236758134307553505349005744813783858296182579499066937623558719053690614036045521106501234382429137090703183214757164738

2/sqrt(pi)=1.12837916709551254903403327002682313814981437866135482297640864330613650124200136292683600692060213139032982650802800120410470018
  
sqrt(2)=1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605

1/sqrt(2)=0.70710678118654752440084436210484903928483593768847403658833986899536623923105351942519376716382078636750692311545614851246241802
  
sqrt(3)=1.73205080756887729352744634150587236694280525381038062805580697945193301690880003708114618675724857567562614141540670302996994509
  
sqrt(5)=2.23606797749978969640917366873127623544061835961152572427089724541052092563780489941441440837878227496950817615077378350425326772
  
sqrt(6)=2.44948974278317809819728407470589139196594748065667012843269256725096037745731502653985943310464023481859460122661418912485886545
  
sqrt(7)=2.64575131106459059050161575363926042571025918308245018036833445920106882323028362776039288647454361061506457833849746309574352988
  
sqrt(8)=2.82842712474619009760337744841939615713934375075389614635335947598146495692421407770077506865528314547002769246182459404984967211
 
sqrt(10)=3.16227766016837933199889354443271853371955513932521682685750485279259443863923822134424810837930029518734728415284005514854885603

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug math/27121] precision error on M_2_SQRTPI
  2020-12-28 11:11 [Bug math/27121] New: precision error on M_2_SQRTPI agepap at yahoo dot com
@ 2020-12-28 14:37 ` adhemerval.zanella at linaro dot org
  2020-12-28 17:42 ` agepap at yahoo dot com
  1 sibling, 0 replies; 3+ messages in thread
From: adhemerval.zanella at linaro dot org @ 2020-12-28 14:37 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27121

Adhemerval Zanella <adhemerval.zanella at linaro dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |adhemerval.zanella at linaro dot o
                   |                            |rg
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
The M_2_SQRTPI is correctly rounded for Binary64/double precision, to get the
correctly rounded 2/sqrt(pi) for float128 you need to use M_2_SQRTPIf128 (it is
a gnu extension so you will need to build with _GNU_SOURCE) added on glibc
2.26.

The following example shows that glibc exported value has the correct precision
for each exported type:

---

$ cat m_2_sqrtpi.c 
#include <mpfr.h>
#include <stdio.h>
#include <math.h>
#include <quadmath.h>

int main (int argc, char *argv[])
{
  const int prec = 4096;
  const mpfr_rnd_t rnd = MPFR_RNDN;

  mpfr_t pi;
  mpfr_init2 (pi, prec);
  mpfr_const_pi (pi, rnd);

  mpfr_t sqrtpi;
  mpfr_init2 (sqrtpi, prec);
  mpfr_sqrt (sqrtpi, pi, rnd);

  mpfr_t two;
  mpfr_init2 (two, prec);
  mpfr_set_d (two, 2.0, rnd);

  mpfr_t ret;
  mpfr_init2 (ret, prec);
  mpfr_div (ret, two, sqrtpi, rnd);

  mpfr_printf ("M_2_SQRTPI (mpfr)      = %.128Ra\n", ret);
  double ret_d = mpfr_get_d (ret, rnd);

  printf ("M_2_SQRTPI (mpfr)      = %a\n", ret_d);
  printf ("M_2_SQRTPI (glibc)     = %a\n", M_2_SQRTPI);

  {
    __float128 ret_f128 = mpfr_get_float128 (ret, rnd);
    char buf[128];
    quadmath_snprintf (buf, sizeof buf, "%Qa", ret_f128);
    printf ("M_2_SQRTPIf128 (mpfr)  = %s\n", buf);
  }

  {
    __float128 ret_f128 = M_2_SQRTPIf128;
    char buf[128];
    quadmath_snprintf (buf, sizeof buf, "%Qa", ret_f128);
    printf ("M_2_SQRTPIf128 (glibc) = %s\n", buf);
  }

  return 0;
}
$ gcc -Wall m_2_sqrtpi.c -D_GNU_SOURCE -DMPFR_WANT_FLOAT128=1 -lquadmath -lmpfr
-o m_2_sqrtpi && ./m_2_sqrtpi 
M_2_SQRTPI (mpfr)      =
0x1.20dd750429b6d11ae3a914fed7fd8688281341d7587cea2e7342b06199cc416180eb39f0b24e1e2281806c12d98f35d77a3e9ddc91c394f0e9eedf0efffd84a3p+0
M_2_SQRTPI (mpfr)      = 0x1.20dd750429b6dp+0
M_2_SQRTPI (glibc)     = 0x1.20dd750429b6dp+0
M_2_SQRTPIf128 (mpfr)  = 0x1.20dd750429b6d11ae3a914fed7fep+0
M_2_SQRTPIf128 (glibc) = 0x1.20dd750429b6d11ae3a914fed7fep+0

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug math/27121] precision error on M_2_SQRTPI
  2020-12-28 11:11 [Bug math/27121] New: precision error on M_2_SQRTPI agepap at yahoo dot com
  2020-12-28 14:37 ` [Bug math/27121] " adhemerval.zanella at linaro dot org
@ 2020-12-28 17:42 ` agepap at yahoo dot com
  1 sibling, 0 replies; 3+ messages in thread
From: agepap at yahoo dot com @ 2020-12-28 17:42 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27121

--- Comment #2 from Angelos Papachristou <agepap at yahoo dot com> ---
Ok there was an error in python that produced wrong results

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-28 17:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-28 11:11 [Bug math/27121] New: precision error on M_2_SQRTPI agepap at yahoo dot com
2020-12-28 14:37 ` [Bug math/27121] " adhemerval.zanella at linaro dot org
2020-12-28 17:42 ` agepap at yahoo dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).