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


Groups > comp.lang.forth > #58082

Re: mixed double and single signed division

From "HAA" <someone@microsoft.com>
Newsgroups comp.lang.forth
Subject Re: mixed double and single signed division
Date 2017-04-25 20:00 +1000
Organization Aioe.org NNTP Server
Message-ID <odn6ol$snt$1@gioia.aioe.org> (permalink)
References <bbcfd72a-4597-4839-aba0-3d4b98009995@googlegroups.com><odh5gb$1j9o$1@gioia.aioe.org><f329796d-80db-46d1-b906-280f0d128036@googlegroups.com><raKdnb7em9WBpGDFnZ2dnUU7-LXNnZ2d@supernews.com><odjigo$18j3$1@gioia.aioe.org><aYmdndPdrNkU0mDFnZ2dnUU7-YXNnZ2d@supernews.com><odjpmd$1nad$1@gioia.aioe.org><yqqdnZOMUcph5WDFnZ2dnUU7-bPNnZ2d@supernews.com><odmdoe$1ojj$1@gioia.aioe.org> <EamdnXN2NouenGLFnZ2dnUU7-SGdnZ2d@supernews.com>

Show all headers | View raw


Elizabeth D. Rather wrote:
> On 4/24/17 4:53 PM, HAA wrote:
> > Elizabeth D. Rather wrote:
> >> On 4/23/17 4:59 PM, HAA wrote:
> >>> Elizabeth D. Rather wrote:
> >>>> ...
> >>>> Which ones have you encountered in your work?
> >>>>
> >>>>> That was the impetus behind the Forth-83 floored-division sweep.  It's
> >>>>> just that they went overboard with the idea and ignored realities such as
> >>>>> conventional and hardware division.
> >>>>
> >>>> Yes, they were all theory-based.
> >>>>
> >>>> Cheers,
> >>>> Elizabeth
> >>>
> >>> Convert number to engineering notation.
> >>> exp' = new exponent,  mod =  #places to shift decimal point.
> >>>
> >>> : >eng ( exp -- mod exp' )  s>d 3 fm/mod 3 * ;
> >>>
> >>> : test  -10 10 do  cr i 4 .r  i >eng  4 .r  4 .r  -1 +loop ;
> >>>
> >>> test
> >>>   10   9   1
> >>>    9   9   0
> >>>    8   6   2
> >>>    7   6   1
> >>>    6   6   0
> >>>    5   3   2
> >>>    4   3   1
> >>>    3   3   0
> >>>    2   0   2
> >>>    1   0   1
> >>>    0   0   0
> >>>   -1  -3   2
> >>>   -2  -3   1
> >>>   -3  -3   0
> >>>   -4  -6   2
> >>>   -5  -6   1
> >>>   -6  -6   0
> >>>   -7  -9   2
> >>>   -8  -9   1
> >>>   -9  -9   0
> >>>  -10 -12   2 ok
> >>
> >> You've actually done this in an application, or is this just another
> >> hypothetical? The number conversions I've seen don't do it that way.
> >>
> >> Cheers,
> >> Elizabeth
> >
> > AFAIK there is no easier way to accomplish it.  If you didn't do it that
> > way, perhaps it's because you didn't recognize that you could.
> >
> > Yes, I've used it - as does most every forth which implements f/p
> > engineering display.
>
> If you're using floating point, you don't care about signed MODs.
>
> Cheers,
> Elizabeth

You care about printing f/p numbers in engineering format.  Below is the
code from SwiftForth's fpmath.f using floored division to adjust the exponent:

    : Adjust ( n - n' 1|2|3 )
       S>D 3 FM/MOD 3 * SWAP 1+  ;

Here's another practical use of floored division.  You need to increment
or decrement date/time by seconds.  Floored division does this easily:

    \ increment or decrement stored date/time in seconds
    : +SECONDS ( secs -- )
      seconds @ +  s>d secs/day fm/mod  jdays +!  seconds ! ;




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


Thread

mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-22 08:21 -0700
  Re: mixed double and single signed division NN <november.nihal@gmail.com> - 2017-04-22 09:14 -0700
    Re: mixed double and single signed division NN <november.nihal@gmail.com> - 2017-04-22 09:22 -0700
      Re: mixed double and single signed division Coos Haak <htrofhc@gmail.com> - 2017-04-22 23:31 +0200
        Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-23 06:44 -0700
          Re: mixed double and single signed division hughaguilar96@gmail.com - 2017-04-23 13:24 -0700
      Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-23 06:41 -0700
        Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-23 13:29 -0700
  Re: mixed double and single signed division Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-04-22 11:40 -0500
    Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-23 06:52 -0700
  Re: mixed double and single signed division "HAA" <someone@microsoft.com> - 2017-04-23 13:02 +1000
    Re: mixed double and single signed division "Elizabeth D. Rather" <erather@forth.com> - 2017-04-22 17:58 -1000
      Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-23 13:36 -0700
        Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-23 16:33 -0700
          Re: mixed double and single signed division anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-24 13:23 +0000
            Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-24 18:49 -0700
        Re: mixed double and single signed division anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-24 13:12 +0000
          Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-24 18:35 -0700
            Re: mixed double and single signed division "Elizabeth D. Rather" <erather@forth.com> - 2017-04-24 15:52 -1000
              Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-25 02:18 -0700
              Re: mixed double and single signed division Paul Rubin <no.email@nospam.invalid> - 2017-04-25 02:25 -0700
                Re: mixed double and single signed division anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-25 11:30 +0000
                Re: mixed double and single signed division "Elizabeth D. Rather" <erather@forth.com> - 2017-04-25 08:08 -1000
                Re: mixed double and single signed division anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-26 14:48 +0000
            Re: mixed double and single signed division anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-25 08:40 +0000
              Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-25 02:25 -0700
                Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-25 03:00 -0700
                Re: mixed double and single signed division anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-25 11:37 +0000
                Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-25 05:27 -0700
                Re: mixed double and single signed division anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-04-25 13:34 +0000
                Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-25 15:29 -0700
                Re: mixed double and single signed division "HAA" <someone@microsoft.com> - 2017-04-27 14:02 +1000
                Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-27 16:00 -0700
                Re: mixed double and single signed division "Elizabeth D. Rather" <erather@forth.com> - 2017-04-27 19:20 -1000
                Re: mixed double and single signed division "HAA" <someone@microsoft.com> - 2017-04-28 22:41 +1000
            Re: mixed double and single signed division Coos Haak <htrofhc@gmail.com> - 2017-04-25 15:32 +0200
              Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-25 15:22 -0700
    Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-23 06:55 -0700
      Re: mixed double and single signed division "Elizabeth D. Rather" <erather@forth.com> - 2017-04-23 13:30 -1000
        Re: mixed double and single signed division krishna.myneni@ccreweb.org - 2017-04-23 16:45 -0700
        Re: mixed double and single signed division "HAA" <someone@microsoft.com> - 2017-04-24 10:56 +1000
          Re: mixed double and single signed division "Elizabeth D. Rather" <erather@forth.com> - 2017-04-23 15:06 -1000
            Re: mixed double and single signed division hughaguilar96@gmail.com - 2017-04-23 19:10 -0700
            Re: mixed double and single signed division Paul Rubin <no.email@nospam.invalid> - 2017-04-23 19:12 -0700
              Re: mixed double and single signed division "Elizabeth D. Rather" <erather@forth.com> - 2017-04-23 16:31 -1000
                Re: mixed double and single signed division hughaguilar96@gmail.com - 2017-04-23 21:17 -0700
                Re: mixed double and single signed division Paul Rubin <no.email@nospam.invalid> - 2017-04-23 21:47 -0700
                Re: mixed double and single signed division hughaguilar96@gmail.com - 2017-04-23 22:58 -0700
                Re: mixed double and single signed division hughaguilar96@gmail.com - 2017-04-23 23:22 -0700
                Re: mixed double and single signed division Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-04-24 04:46 -0500
            Re: mixed double and single signed division "HAA" <someone@microsoft.com> - 2017-04-24 12:59 +1000
              Re: mixed double and single signed division "Elizabeth D. Rather" <erather@forth.com> - 2017-04-23 18:03 -1000
                Re: mixed double and single signed division hughaguilar96@gmail.com - 2017-04-23 21:22 -0700
                Re: mixed double and single signed division "HAA" <someone@microsoft.com> - 2017-04-25 12:53 +1000
                Re: mixed double and single signed division "Elizabeth D. Rather" <erather@forth.com> - 2017-04-24 21:55 -1000
                Re: mixed double and single signed division "HAA" <someone@microsoft.com> - 2017-04-25 20:00 +1000

csiph-web