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


Groups > comp.lang.forth > #135347

Re: Range Reduction Using Big Number Arithmetic

From Krishna Myneni <krishna.myneni@ccreweb.org>
Newsgroups comp.lang.forth
Subject Re: Range Reduction Using Big Number Arithmetic
Date 2026-08-15 07:48 -0500
Organization A noiseless patient Spider
Message-ID <115pn6e$3cout$1@dont-email.me> (permalink)
References <115pm90$3cl9h$1@dont-email.me>

Show all headers | View raw


On 8/15/26 07:32, Krishna Myneni wrote:
> A simple Forth implementation for reducing large angles (|x| > 500000 
> rad) for accurate evaluation by the x87 native fpu trig instructions 
> FSIN FCOS FSINCOS FTAN is given below. The Forth code relies on the 
> Forth Scientific Library (FSL #47) big number arithmetic module.
> 
...
> === begin rr-big.4th ===
> \ rr-big.4th
> \
> \ Perform range reduction of large angle x (radians) for
> \ accurate trigonometric functions with x87 using the FSL
> \ big number arithmetic module.
> \
> \ K. Myneni, 2026-08-15
> \
> \ Notes:
> \ 1. Angles |x| < DP_RR_CUTOFF are not reduced. The
> \      native x87 trig functions are accurate.
> \
> \ 2. Range reduction is valid over the range,
> \    |x| < DP_RR_MAX_ANGLE
> \
> include ans-words
> include modules
> include ieee-754
> include fsl/big
> include fsl/extras/big-extras
> 
> 8 constant BIG_DBL
> 5.0e05 fconstant   DP_RR_CUTOFF
> 9.2e18 fconstant   DP_RR_MAX_ANGLE
> 
> \ BIG number constants and variables
> create  5^52    BIG_DBL CELLS allot   5 52 big_s^n  5^52 big-move
> create 10^52    BIG_DBL CELLS allot  10 52 big_s^n 10^52 big-move
> create BIG_2PI  BIG_DBL CELLS allot
> big 62831853071795864769252867665590057683943387987502116
> BIG_2PI big-move
> 
> : exponent ( F: r -- ) ( -- n ) fexponent 1023 - ;
> 
> variable m
> : freduce-range ( F: r1 -- r2)
>      \ Store sign, perform error checks
>      fdup f0< >r  ( R: bsign)
>      fabs
>      fdup DP_RR_CUTOFF f< IF
>        r> IF fnegate THEN EXIT  \ no rr correction
>      THEN
>      fdup DP_RR_MAX_ANGLE f> IF  \ exceed limit of algorithm
>        cr ." Angle out of range." cr
>        -46 throw
>      THEN
>      fdup PI 2e f* f/ ftrunc>s m ! \ multiple of 2pi
> 
>      \ Perform range reduction
>      fdup ffraction drop >r big-here dup 5^52 big>here
>      r> big*s 10^52 big+ >r  ( R: abig bsign) ( F: r)
>      exponent 1 swap lshift
>      r@ swap big*s
>      r> r> IF bignegate THEN
>      big-here dup BIG_2PI big>here m @ big*s
>      big-
>      dup big0< swap dup bigabs <big# big#s swap bigsign #big>
>      >float IF
>         1.0e-52 f*
>      ELSE
>        ." Conversion to double-precision float error!"
>        0e
>      THEN
> ;
> === end rr-big.4th ===
> 

I forgot to mention that the code above assumes a 64-bit Forth system 
with a separate fp stack.

--
KM

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