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


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

Re: BASIC oddity?

From Martin <News03@avisoft.f9.co.uk>
Subject Re: BASIC oddity?
Newsgroups comp.sys.acorn.programmer
Date 2020-01-04 16:08 +0000
Message-ID <582d216fd8News03@avisoft.f9.co.uk> (permalink)
References <4adaa32c58.Alan.Adams@ArmX6.adamshome.org.uk> <582cb030b8News03@avisoft.f9.co.uk> <quoa19$o6o$1@dont-email.me> <ef3ac02c58.Alan.Adams@ArmX6.adamshome.org.uk> <qupq4i$4nf$1@gioia.aioe.org>
Organization None

Show all headers | View raw


On 04 Jan in article <qupq4i$4nf$1@gioia.aioe.org>,
   Steve Drain <steve@kappa.me.uk> wrote:
> druck wrote:

> > I'd always opt for a bit of assembler to do that, as its every
> > easy to do arbitrary sized arithmetic when you've got access to
> > the CPU flags.

> +1

> > But anyway this highlights the lack of date and time manipulation 
> > SWIs in RISC OS. The only things you can do with a 5 byte time is 
> > convert it to or from a string.

> I approached this lack ages ago in Basalt, which has a
> comprehensive set of datetime keywords. 5-byte datetime values are
> held in float variables, but the float value is meaningless except
> when used with appropriate keywords.

> So, you could do:

>   interval%=SECONDS(datetime2 - datetime1)

> ;-)

> Maybe I could develop a module from this.

I have thought about this again, and re-read Alan's original post
more carefully. I would agree with druck's suggestion (although I did
not see his full post) that using assembler to subtract the full 5
bytes correctly is undoubtedly the best way to ensure that all
possible values are catered for correctly.

However, two points should be considered from Alan's post.

1.  The answer is a relatively small positive time difference. 
    If 1 day maximum, this is only 8,640,000 or &83D600.
    The MSB 5th byte only changes about every 500 days.

2.  Alan said
> The weird example is the third, where subtracting a very large
> positive number from a very large negative number produces a
> positive result.
But this result is not weird, it is correct - because as they are
both UNSIGNED it is subtracting a very large number from an even
larger number. The result is a small number, which is correct. 

The strange thing about 2's complement arithmetic is that it works
for both signed and unsigned numbers. The first 4 bytes of a 5-byte
time block are unsigned, so cannot be regarded as negative. It even
works when the MSB 5th byte has changed, as the last example shows.

So, I would suggest that using 
    I% = !buf1%
    J% = !buf2%
    K% = I%-J%
will suffice to calculate a time difference of a few days in cs.

... unless anyone can see the flaws in my argument!

-- 
Martin Avison 
Note that unfortunately this email address will become invalid
without notice if (when) any spam is received. 

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


Thread

BASIC oddity? Alan Adams <alan@adamshome.org.uk> - 2020-01-03 17:16 +0000
  Re: BASIC oddity? Martin <News03@avisoft.f9.co.uk> - 2020-01-03 19:31 +0000
    Re: BASIC oddity? druck <news@druck.org.uk> - 2020-01-03 21:00 +0000
      Re: BASIC oddity? Alan Adams <alan@adamshome.org.uk> - 2020-01-03 22:26 +0000
        Re: BASIC oddity? Steve Drain <steve@kappa.me.uk> - 2020-01-04 10:40 +0000
          Re: BASIC oddity? Martin <News03@avisoft.f9.co.uk> - 2020-01-04 16:08 +0000
            Re: BASIC oddity? Alan Adams <alan@adamshome.org.uk> - 2020-01-04 16:22 +0000
              Re: BASIC oddity? David Higton <dave@davehigton.me.uk> - 2020-01-04 17:24 +0000
                Re: BASIC oddity? Alan Adams <alan@adamshome.org.uk> - 2020-01-04 18:47 +0000
                Re: BASIC oddity? Matthew Phillips <spam2011m@yahoo.co.uk> - 2020-01-06 08:58 +0000
                Re: BASIC oddity? David Higton <dave@davehigton.me.uk> - 2020-01-06 16:20 +0000
                Re: BASIC oddity? Matthew Phillips <spam2011m@yahoo.co.uk> - 2020-01-07 08:49 +0000
                Re: BASIC oddity? Martin <News03@avisoft.f9.co.uk> - 2020-01-07 11:20 +0000
                Re: BASIC oddity? David Higton <dave@davehigton.me.uk> - 2020-01-07 15:05 +0000
                Re: BASIC oddity? Matthew Phillips <spam2011m@yahoo.co.uk> - 2020-01-08 08:23 +0000
                Re: BASIC oddity? Alan Adams <alan@adamshome.org.uk> - 2020-01-08 10:26 +0000
                Re: BASIC oddity? druck <news@druck.org.uk> - 2020-01-08 21:02 +0000
                Re: BASIC oddity? Richard Ashbery <basura@invalid.addr.uk> - 2020-01-09 12:53 +0000
                Re: BASIC oddity? Steve Fryatt <news@stevefryatt.org.uk> - 2020-01-09 23:16 +0000
                Re: BASIC oddity? Steve Fryatt <news@stevefryatt.org.uk> - 2020-01-08 22:35 +0000
                Re: BASIC oddity? Martin <News03@avisoft.f9.co.uk> - 2020-01-08 23:51 +0000
          Re: BASIC oddity? Steve Drain <steve@kappa.me.uk> - 2020-01-10 11:30 +0000
            Re: BASIC oddity? Alan Adams <alan@adamshome.org.uk> - 2020-01-10 12:38 +0000
      Re: BASIC oddity? Jean-Michel <jmc.bruck@orange.fr> - 2020-01-06 20:39 +0100
        Re: BASIC oddity? Alan Adams <alan@adamshome.org.uk> - 2020-01-06 21:13 +0000
          Re: BASIC oddity? Steve Drain <steve@kappa.me.uk> - 2020-01-08 12:46 +0000

csiph-web