Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #135631

Re: Range Reduction Using Big Number Arithmetic

From peter <peter.noreply@tin.it>
Newsgroups comp.lang.forth
Subject Re: Range Reduction Using Big Number Arithmetic
Date 2026-09-09 18:49 +0200
Organization A noiseless patient Spider
Message-ID <20260909184929.0000509e@tin.it> (permalink)
References <115pm90$3cl9h$1@dont-email.me> <1168f21$bnk$1@dont-email.me> <116sa3b$2dpj8$4@dont-email.me> <117cuca$4f48$1@dont-email.me> <117rjv3$14ov3$1@dont-email.me>

Show all headers | View raw


On Wed, 9 Sep 2026 07:37:55 -0500
Krishna Myneni <krishna.myneni@ccreweb.org> wrote:

> On 9/3/26 6:03 PM, Krishna Myneni wrote:
> > On 8/28/26 10:39, Krishna Myneni wrote:
> ...
> >>>> If you are using a C-based Forth, the libc function may or may not 
> >>>> provide range-reduction. Comparison with the GNU library function
> >>>>
> >>>> sin( x ),
> >>>>
> >>>> which does perform range-reduction is shown in the test results.
> >>>>
> >> ...
> >> One can examine the glibc code for double precision sin(x) at the link 
> >> below.
> >>
> >> https://github.com/bminor/glibc/ 
> >> blob/6059938728a98270b9706488887f43baa0471eba/sysdeps/ieee754/dbl-64/ 
> >> s_sin.c
> >>
> >> === clip from above file ===
> >> ...
> >> /*******************************************************************/
> >> /* An ultimate sin routine. Given an IEEE double machine number x  */
> >> /* it computes the rounded value of sin(x).               */
> >> /*******************************************************************/
> >> #ifndef IN_SINCOS
> >> double
> >> SECTION
> >> __sin (double x)
> >> {
> >> ...
> >> === end of clip ===
> >>
> >> There are several ranges of the input parameter x, each of which are 
> >> handled differently:
> >>
> >> I. 2^-26 < |x| < 0.855469;  no range reduction needed
> >>
> >> II. 0.855469  < |x| < 2.426265; ?
> >>
> >> III. 2.426265 < |x| < 105414350; uses function reduce_sincos()
> >>
> >> IV.  105414350 < |x| < 2^1024; uses function _branred()
> >>
> >> V. 105414350 < |x| < 2^1024; set error condition
> >>
> >>
> ...
> > I've studied the branred.c code from glibc (version 2.4.2.9000, from 
> > Github repo bminor/glibc), and I've made a stand-alone set of files 
> > which compile to provide accurate, range-reduced sin(x) and cos(x) 
> > functions -- yes, it works at x=1e100 rad!
> > 
> > The interesting part is that branred() uses double-double floating point 
> > arithmetic (which provides a 106-bit significand, over an exponent range 
> > the same as ordinary double-precision). Consequently, the glibc code for 
> > sin(x) and cos(x) functions set the fpu precision and rounding mode to 
> > double-precision and round to nearest, in order for double-double 
> > precision arithmetic to work.
> > ...
> 
> I have extracted the necessary files from glibc and modified them to 
> make standalone object files for high accuracy sin(x) and cos(x) 
> computation with full-range double-precision args and tested them under 
> gcc linux x86 and Digital Mars C++ compilers.
> 
> kForth-Win32 will soon get an upgrade for its FSIN and FCOS words.

An alternative is to use the files from the Core-Math project

https://gitlab.inria.fr/core-math/core-math

They are claimed to be correctly rounded, my tests also show this.
They are bloated and will compile to a large object file.
I have seen that also glibc has started to use selected files from them.

BR
Peter


> Krishna
> 

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-08-15 07:32 -0500
  Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-08-15 07:48 -0500
  Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-08-20 22:01 -0500
    Re: Range Reduction Using Big Number Arithmetic albert@spenarnc.xs4all.nl - 2026-08-22 19:31 +0200
      Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-08-31 08:49 -0500
    Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-08-28 10:39 -0500
      Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-08-28 10:42 -0500
      Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-03 18:03 -0500
        Re: Range Reduction Using Big Number Arithmetic marcel hendrix <mhx@iae.nl> - 2026-09-04 07:29 +0200
          Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-04 07:45 -0500
            Re: Range Reduction Using Big Number Arithmetic marcel hendrix <mhx@iae.nl> - 2026-09-04 15:29 +0200
              Re: Range Reduction Using Big Number Arithmetic albert@spenarnc.xs4all.nl - 2026-09-05 12:27 +0200
                Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-05 08:39 -0500
        Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-09 07:37 -0500
          Re: Range Reduction Using Big Number Arithmetic peter <peter.noreply@tin.it> - 2026-09-09 18:49 +0200
            Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-09 15:06 -0500
            Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-10 19:03 -0500
              Re: Range Reduction Using Big Number Arithmetic peter <peter.noreply@tin.it> - 2026-09-11 14:56 +0200
                Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-11 09:17 -0500
                Re: Range Reduction Using Big Number Arithmetic peter <peter.noreply@tin.it> - 2026-09-11 17:04 +0200
                Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-11 10:46 -0500
                Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-11 13:24 -0500
                Re: Range Reduction Using Big Number Arithmetic peter <peter.noreply@tin.it> - 2026-09-11 23:21 +0200
                Re: Range Reduction Using Big Number Arithmetic peter <peter.noreply@tin.it> - 2026-09-12 00:42 +0200
                Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-11 18:33 -0500
                Re: Range Reduction Using Big Number Arithmetic peter <peter.noreply@tin.it> - 2026-09-12 11:04 +0200
                Re: Range Reduction Using Big Number Arithmetic Krishna Myneni <krishna.myneni@ccreweb.org> - 2026-09-12 10:33 -0500

csiph-web