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


Groups > comp.sys.acorn.programmer > #5698

Re: Sine/Cosine/Tangent accuracy error

From Martin Wuerthner <spamtrap@mw-software.com>
Newsgroups comp.sys.acorn.programmer
Subject Re: Sine/Cosine/Tangent accuracy error
Date 2019-02-26 17:17 +0100
Organization MW Software
Message-ID <mpro.pnjjww01l45o706b4.spamtrap@mw-software.com> (permalink)
References <578aeb07c9basura@invalid.addr.uk> <q4v9ot$qe5$1@dont-email.me> <578bf8b556basura@invalid.addr.uk>

Show all headers | View raw


Richard Ashbery <basura@invalid.addr.uk> wrote:

> In article <q4v9ot$qe5$1@dont-email.me>, druck <news@druck.org.uk> wrote:
> > On 23/02/2019 16:28, Richard Ashbery wrote:
> > > I have a very old but interesting BASIC graphic program where I've
> > > made some minor changes to operate on a 1920 x 1080 res monitor.
> > > 
> > > After program is run for some minutes it errors with "Accuracy lost in
> > > Sine/Cosine/Tangent".
> > > 
> > > How do I stop this error from appearing?
> 
> > If you are continually incrementing an angle which gets used in
> > SIN/COS/TAN, take a modulus to prevent it getting to big.
> 
> > e.g. If you are incrementing angle variable 'a' degrees
> 
> > a = (a + 1) MOD 360
> 
> > Or for radians.
> 
> > a = (a + 0.01) MOD (2*PI)

Not such a good idea for radians, since MOD is an integer operator, so it
will round its argument to a whole number and return a whole number.

> I've submitted the program for your perusal. The idea is quite simple but
> I can't get my head round the programming :-(
>     [...]
>     A=SIDE*2*PI/S:A=A+B
>     PRINT TAB(10,10)A
>     X1=SIZE*COS A:Y1=SIZE*SIN A

Instead of the last line, use:

      REM range reduce the argument
      RR = A - INT(A / (2 * PI)) * 2 * PI
      X1=SIZE*COS RR:Y1=SIZE*SIN RR

-- 
Martin Wuerthner         MW Software      http://www.mw-software.com/

------- RISC OS Software for Design, Printing and Publishing --------

Back to comp.sys.acorn.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Sine/Cosine/Tangent accuracy error Richard Ashbery <basura@invalid.addr.uk> - 2019-02-23 16:28 +0000
  Re: Sine/Cosine/Tangent accuracy error Steve Fryatt <news@stevefryatt.org.uk> - 2019-02-23 17:55 +0000
    Re: Sine/Cosine/Tangent accuracy error Richard Ashbery <basura@invalid.addr.uk> - 2019-02-23 20:53 +0000
      Re: Sine/Cosine/Tangent accuracy error Steve Fryatt <news@stevefryatt.org.uk> - 2019-02-24 08:25 +0000
        Re: Sine/Cosine/Tangent accuracy error Richard Ashbery <basura@invalid.addr.uk> - 2019-02-24 12:20 +0000
  Re: Sine/Cosine/Tangent accuracy error druck <news@druck.org.uk> - 2019-02-24 23:35 +0000
    Re: Sine/Cosine/Tangent accuracy error Richard Ashbery <basura@invalid.addr.uk> - 2019-02-25 17:34 +0000
      Re: Sine/Cosine/Tangent accuracy error Martin Wuerthner <spamtrap@mw-software.com> - 2019-02-26 17:17 +0100
        Re: Sine/Cosine/Tangent accuracy error jgh@mdfs.net - 2019-02-26 12:46 -0800
        Re: Sine/Cosine/Tangent accuracy error Richard Ashbery <basura@invalid.addr.uk> - 2019-02-27 16:37 +0000
        Re: Sine/Cosine/Tangent accuracy error druck <news@druck.org.uk> - 2019-02-27 20:27 +0000

csiph-web