Triple words added

25 views
Skip to first unread message

The Beez

unread,
May 12, 2015, 4:23:58 PM5/12/15
to 4th-co...@googlegroups.com
Hi 4tH-ers!

A little news from the front. In Europe we now got bank account numbers called "IBAN" with which you can send money all around the EU. There are a lot of shady websites around for conversion and validation of these numbers. So I thought I'd better do some of that offline. How hard can it be? Well, it isn't but the length of the number is such, that even 64bit numbers just don't work.

So I wondered whether I could het 96bit numbers (or better). I got a few pointers, but nothing that got me going. So, I decided to do it myself. In our own ANS-Forth there are a few triple routines, but nothing complete. I also found some things in ColdForth - again, not enough. But throwing it all together, I slowly got something going. Enough to make my IBAN stuff.

Then I wondered how far I could take this thing. I studied the DOUBLE and MIXED words and that was inspiring. A little experimentation was all I needed - although testing was rather painful. For this you seriously need http://keisan.casio.com/has10/Free.cgi - there is nothing like it. Ordinary calculators just don't do it for me, since even the best are too inaccurate.

So, now we got an almost full range of words, including I/O (<T# and S>TRIPLE to give you an idea). I haven't seen it anywhere else yet.

\ t+        Triple addition            ( t1 t2 -- t3 )
\ tnegate   Triple negation            ( t -- -t )
\ t-        Triple subtraction         ( t1 t2 -- t3 )
\ tabs      Triple absolute            ( t -- |t| )
\ t0=       Triple equal zero          ( t -- f)
\ t0<       Triple less than zero      ( t -- f)
\ t<        Triple smaller than triple ( t1 t2 -- f)
\ ut*       Double with unsigned       ( ud u -- t )
\ tu*       Triple with unsigned       ( ut u -- t)
\ mt*       Double with signed         ( d n -- t )
\ ut/mod    Divide triple by signed.   ( ut1 n -- urem d )
\ tu/mod    Divide triple by unsigned  ( ut1 t -- urem ut2)


Source in SVN, have fun!

Hans Bezemer

The Beez

unread,
May 13, 2015, 4:57:09 AM5/13/15
to 4th-co...@googlegroups.com, the.bee...@gmail.com


On Tuesday, May 12, 2015 at 10:23:58 PM UTC+2, The Beez wrote:
BTW, I knicked the T+ word from ANS float - and gave proper credit of course, but that's just a side line - and got a problem there. Of course, I could have renamed the word, but it's the same and make things confusing and less readable. I could have put it in a separate library, but note this thing is instrumental in the proper workings of ANS float. If - for whatever reason - that word got changed in the flow of time it could cripple ANS float. So I decided not to follow this path.

I tried several schemes, but always ran into scenarios where it COULD go wrong. So I decided to do it in the only way which worked: you have to include the triple library AFTER ANS float if you want to combine them. It's of course properly documented, but it's still a kludge - but a workable kludge.

There are very few places where the order of inclusion of include files matter, e.g. dynamic memory (the MEM---- family), number conversion (>NUMBER in single or double variants) and now ANS float and triple. Sorry for that. However, if you violate this rule, the compiler will bomb out with an appropriate message.

If you have any better ideas, I'd be happy to hear from you.

Hans Bezemer


Reply all
Reply to author
Forward
0 new messages