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


Groups > comp.lang.forth > #57822 > unrolled thread

mixed double and single signed division

Started bykrishna.myneni@ccreweb.org
First post2017-04-22 08:21 -0700
Last post2017-04-25 20:00 +1000
Articles 16 on this page of 56 — 9 participants

Back to article view | Back to comp.lang.forth


Contents

  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

Page 3 of 3 — ← Prev page 1 2 [3]


#57937

From"HAA" <someone@microsoft.com>
Date2017-04-24 10:56 +1000
Message-ID<odjigo$18j3$1@gioia.aioe.org>
In reply to#57929
Elizabeth D. Rather wrote:
> On 4/23/17 3:55 AM, krishna.myneni@ccreweb.org wrote:
> > On Saturday, April 22, 2017 at 10:02:38 PM UTC-5, HAA wrote:
> > ...
> >> 'Starting Forth' was polyForth where all the MOD words were unsigned.  My guess is
> >> as there was no equivalent of FM/MOD or SM/REM for users to NIP, they provided M/ .
> >
> > Yes, Starting Forth has UM/MOD but no signed equivalent.
>
> That's because no one suggested any likely application scenarios that
> benefit from or require a signed M/MOD. Most of the time when you
> dealing with a MOD you're doing something inherently unsigned.
>
> Cheers,
> Elizabeth

Hard to believe you've never encountered situations involving a negative
dividend, positive divisor, requiring a positive mod.

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.


[toc] | [prev] | [next] | [standalone]


#57938

From"Elizabeth D. Rather" <erather@forth.com>
Date2017-04-23 15:06 -1000
Message-ID<aYmdndPdrNkU0mDFnZ2dnUU7-YXNnZ2d@supernews.com>
In reply to#57937
On 4/23/17 2:56 PM, HAA wrote:
> Elizabeth D. Rather wrote:
>> On 4/23/17 3:55 AM, krishna.myneni@ccreweb.org wrote:
>>> On Saturday, April 22, 2017 at 10:02:38 PM UTC-5, HAA wrote:
>>> ...
>>>> 'Starting Forth' was polyForth where all the MOD words were unsigned.  My guess is
>>>> as there was no equivalent of FM/MOD or SM/REM for users to NIP, they provided M/ .
>>>
>>> Yes, Starting Forth has UM/MOD but no signed equivalent.
>>
>> That's because no one suggested any likely application scenarios that
>> benefit from or require a signed M/MOD. Most of the time when you
>> dealing with a MOD you're doing something inherently unsigned.
>>
>> Cheers,
>> Elizabeth
>
> Hard to believe you've never encountered situations involving a negative
> dividend, positive divisor, requiring a positive mod.

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

-- 
Elizabeth D. Rather
FORTH, Inc.
6080 Center Drive, Suite 600
Los Angeles, CA  90045
USA

[toc] | [prev] | [next] | [standalone]


#57943

Fromhughaguilar96@gmail.com
Date2017-04-23 19:10 -0700
Message-ID<4277e5d6-45e0-41cc-a632-0c88f8c48f40@googlegroups.com>
In reply to#57938
On Sunday, April 23, 2017 at 6:06:23 PM UTC-7, Elizabeth D. Rather wrote:
> On 4/23/17 2:56 PM, HAA wrote:
> > Elizabeth D. Rather wrote:
> >> That's because no one suggested any likely application scenarios that
> >> benefit from or require a signed M/MOD. Most of the time when you
> >> dealing with a MOD you're doing something inherently unsigned.
> >
> > Hard to believe you've never encountered situations involving a negative
> > dividend, positive divisor, requiring a positive mod.
> 
> Which ones have you encountered in your work?

: dow { month day year | K J -- str }               \ Zeller's Algorithm: http://calendars.wikia.com/wiki/Zeller's_congruence
    month 3 < if  12 +to month  -1 +to year  then
    year 100 /mod  to J  to K
    month 1 +  13 *  5 /    
    day +                   
    K +                     
    K 4 / +                 
    J 4 / +                 
    J 5 * +                 
    1 -  7 mod  days ;

[toc] | [prev] | [next] | [standalone]


#57944

FromPaul Rubin <no.email@nospam.invalid>
Date2017-04-23 19:12 -0700
Message-ID<87a876tuyt.fsf@nightsong.com>
In reply to#57938
"Elizabeth D. Rather" <erather@forth.com> writes:
> Which ones have you encountered in your work?

This happens all the time.  Like it's currently April (the 4th month of
the year) and suppose you want to know what month it was 6 months ago.
With floored mod, (4-6) mod 12 is 10, so it was October.  With signed
mod, it was the month -2, which is less informative.

[toc] | [prev] | [next] | [standalone]


#57945

From"Elizabeth D. Rather" <erather@forth.com>
Date2017-04-23 16:31 -1000
Message-ID<ioCdncMS6-kX_mDFnZ2dnUU7-b_NnZ2d@supernews.com>
In reply to#57944
On 4/23/17 4:12 PM, Paul Rubin wrote:
> "Elizabeth D. Rather" <erather@forth.com> writes:
>> Which ones have you encountered in your work?
>
> This happens all the time.  Like it's currently April (the 4th month of
> the year) and suppose you want to know what month it was 6 months ago.
> With floored mod, (4-6) mod 12 is 10, so it was October.  With signed
> mod, it was the month -2, which is less informative.

If I wanted to know that, there are many easier ways than computing it 
that way. I'm looking for a real-world example, preferably one that 
you've encountered.

Cheers,
Elizabeth

-- 
Elizabeth D. Rather
FORTH, Inc.
6080 Center Drive, Suite 600
Los Angeles, CA  90045
USA

[toc] | [prev] | [next] | [standalone]


#57952

Fromhughaguilar96@gmail.com
Date2017-04-23 21:17 -0700
Message-ID<60bee11b-b22c-4c2f-844a-efb6db18a51a@googlegroups.com>
In reply to#57945
On Sunday, April 23, 2017 at 7:31:43 PM UTC-7, Elizabeth D. Rather wrote:
> On 4/23/17 4:12 PM, Paul Rubin wrote:
> > "Elizabeth D. Rather" <erather@forth.com> writes:
> >> Which ones have you encountered in your work?
> >
> > This happens all the time.  Like it's currently April (the 4th month of
> > the year) and suppose you want to know what month it was 6 months ago.
> > With floored mod, (4-6) mod 12 is 10, so it was October.  With signed
> > mod, it was the month -2, which is less informative.
> 
> If I wanted to know that, there are many easier ways than computing it 
> that way. I'm looking for a real-world example, preferably one that 
> you've encountered.

Elizabeth Rather wants to ban anything that hasn't been used in a Forth Inc. application program. This is why double-precision division was banned from ANS-Forth --- nobody at Forth Inc. at run into the need for it --- then in the year 2009 I need it for my continued-fraction program (actually Nathaniel Grossman needed it in 1984) and her solution is to say that I'm not a Forth programmer and can never become a Forth programmer because I don't understand the Forth Way.

ANS-Forth is a cult! Elizabeth Rather's contribution has been purely negative --- all she does is tell Forth programmers what they can't do --- also, the Forth-200x committee (the "Committee of Can't") that she appointed does the same thing (ban my rquotations as non-standard, although they work under VFX and SwiftForth and could be made to work under almost any Forth system).

[toc] | [prev] | [next] | [standalone]


#57957

FromPaul Rubin <no.email@nospam.invalid>
Date2017-04-23 21:47 -0700
Message-ID<87pog2o1id.fsf@nightsong.com>
In reply to#57945
"Elizabeth D. Rather" <erather@forth.com> writes:
> If I wanted to know that, there are many easier ways than computing it
> that way

What would be an example of an easier way?  It should work for 6 months
earlier, 73 months earlier, 62 months later, etc.

[toc] | [prev] | [next] | [standalone]


#57962

Fromhughaguilar96@gmail.com
Date2017-04-23 22:58 -0700
Message-ID<de6ed990-b45e-4e81-9318-d07f4c7d0a7b@googlegroups.com>
In reply to#57957
On Sunday, April 23, 2017 at 9:47:25 PM UTC-7, Paul Rubin wrote:
> "Elizabeth D. Rather" <erather@forth.com> writes:
> > If I wanted to know that, there are many easier ways than computing it
> > that way
> 
> What would be an example of an easier way?  It should work for 6 months
> earlier, 73 months earlier, 62 months later, etc.

What I have in the novice-package doesn't exactly do that, because it adds days to a particular date, not months --- months vary in the number of days that they have --- so, your code is actually necessary (I'll put it in the novice-package).

This is what I have in the novice-package at this time:
-------------------------------------------------------

\ ****** 
\ ****** This is the day of the week calculator.
\ ****** 

align here ," Saturday"
align here ," Friday"
align here ," Thursday"
align here ," Wednesday"
align here ," Tuesday"
align here ," Monday"
align here ," Sunday"

create <days> , , , , , , ,     \ Sunday=0, Monday=1, ... Saturday=6

: days ( n -- str )
    dup 0<  over 7 >=  or abort" *** DAYS given invalid value ***"
    w *  <days> +  @ ;
    
\ See TOY.4TH for two more implementations, one of which is my own invention.    
    
\ DATE>N and N>DATE both come from: https://alcor.concordia.ca//~gpkatch/gdate-algorithm.html    
\ This is mostly useful when you need add some number of days to a date and get a new date.
    
: date>n { month day year -- n }                    
    month 9 +  12 mod           to month
    year  month 10 /  -         to year
    year 365 *
    year 4 /                    +
    year 100 /                  -
    year 400 /                  +
    month 306 *  5 +  10 /      +
    day 1 -                     + ;
    
: n>dow ( n -- str )                                \ N comes from DATE>N
    3 +  7 mod  days ;

: n>date { n | y mm dd ddd mi -- month day year }   \ N comes from DATE>N
    n 10000 um*  14780. d+  3652425 um/mod nip              to y
    365 y *  y 4 / +  y 100 / -  y 400 / +  n swap -        to ddd
    ddd 0< if
        y 1 -                                               to y
        365 y *  y 4 / +  y 100 / -  y 400 / +  n swap -    to ddd      then
    ddd 100 *  52 +  3060 /                                 to mi
    mi 2 +  12 mod  1 +                                     to mm
    mi 2 +  12 /  y +                                       to y
    mi 306 *  5 +  10 /  ddd swap -  1 +                    to dd
    mm dd y ;
    
: valid-date? ( month day year -- flag )    
    3dup date>n n>date      \ -- m1 d1 y1 m2 d2 y2
    fourth = >r             \ -- m1 d1 y1 m2 d2
    fourth = >r             \ -- m1 d1 y1 m2
    fourth = >r             \ -- m1 d1 y1
    3drop
    r> r> and  r> and ;

[toc] | [prev] | [next] | [standalone]


#57964

Fromhughaguilar96@gmail.com
Date2017-04-23 23:22 -0700
Message-ID<ba2a4a68-c5a9-4a2f-be7a-030a247958cf@googlegroups.com>
In reply to#57962
On Sunday, April 23, 2017 at 10:58:01 PM UTC-7, hughag...@gmail.com wrote:
> On Sunday, April 23, 2017 at 9:47:25 PM UTC-7, Paul Rubin wrote:
> > "Elizabeth D. Rather" <erather@forth.com> writes:
> > > If I wanted to know that, there are many easier ways than computing it
> > > that way
> > 
> > What would be an example of an easier way?  It should work for 6 months
> > earlier, 73 months earlier, 62 months later, etc.
> 
> What I have in the novice-package doesn't exactly do that, because it adds days to a particular date, not months --- months vary in the number of days that they have --- so, your code is actually necessary (I'll put it in the novice-package).

I just noticed that you didn't provide any code. So I wrote it myself. Here is the addition I'll put in the novice-package:

: month+ ( month n -- relative-year new-month )     \ MONTH and NEW-MONTH are in the range [1,12]
    +  1-  s>d                                      \ the 1- is because we need months in the range [0,11]
    12 fm/mod 
    swap 1+ ;

\ MONTH+ was inspired by Paul Rubin in this thread: https://groups.google.com/forum/#!topic/comp.lang.forth/i_F7GtPxjE4        

[toc] | [prev] | [next] | [standalone]


#57981

FromAndrew Haley <andrew29@littlepinkcloud.invalid>
Date2017-04-24 04:46 -0500
Message-ID<gridnS75ffb6VGDFnZ2dnUU7-N_NnZ2d@supernews.com>
In reply to#57945
Elizabeth D. Rather <erather@forth.com> wrote:
> On 4/23/17 4:12 PM, Paul Rubin wrote:
>> "Elizabeth D. Rather" <erather@forth.com> writes:
>>> Which ones have you encountered in your work?
>>
>> This happens all the time.  Like it's currently April (the 4th month of
>> the year) and suppose you want to know what month it was 6 months ago.
>> With floored mod, (4-6) mod 12 is 10, so it was October.  With signed
>> mod, it was the month -2, which is less informative.
> 
> If I wanted to know that, there are many easier ways than computing it 
> that way. I'm looking for a real-world example, preferably one that 
> you've encountered.

The classic one is an angle of rotation, which can lead or lag and
sometimes even exceed 360 degrees, and I have encountered that in real
life.  But if the dividend is negative and all you want is the
remainder, all you have to do is add a multiple of the divisor into
the dividend.  The easiest way to do that is to add the dividend into
the high cell of the divisor and then do the division.

I believe that the argument circa 1981 was about whether MOD words
which can to handle negative dividends should be part of the standard
word set, rather that whether they were occasionally useful.  On the
other hand, I am happy to maintain that calculating the remainder of
anything mod N, N < 0 makes no sense.

Andrew.

[toc] | [prev] | [next] | [standalone]


#57948

From"HAA" <someone@microsoft.com>
Date2017-04-24 12:59 +1000
Message-ID<odjpmd$1nad$1@gioia.aioe.org>
In reply to#57938
Elizabeth D. Rather wrote:
> On 4/23/17 2:56 PM, HAA wrote:
> > Elizabeth D. Rather wrote:
> >> On 4/23/17 3:55 AM, krishna.myneni@ccreweb.org wrote:
> >>> On Saturday, April 22, 2017 at 10:02:38 PM UTC-5, HAA wrote:
> >>> ...
> >>>> 'Starting Forth' was polyForth where all the MOD words were unsigned.  My guess is
> >>>> as there was no equivalent of FM/MOD or SM/REM for users to NIP, they provided M/ .
> >>>
> >>> Yes, Starting Forth has UM/MOD but no signed equivalent.
> >>
> >> That's because no one suggested any likely application scenarios that
> >> benefit from or require a signed M/MOD. Most of the time when you
> >> dealing with a MOD you're doing something inherently unsigned.
> >>
> >> Cheers,
> >> Elizabeth
> >
> > Hard to believe you've never encountered situations involving a negative
> > dividend, positive divisor, requiring a positive mod.
>
> 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


[toc] | [prev] | [next] | [standalone]


#57951

From"Elizabeth D. Rather" <erather@forth.com>
Date2017-04-23 18:03 -1000
Message-ID<yqqdnZOMUcph5WDFnZ2dnUU7-bPNnZ2d@supernews.com>
In reply to#57948
On 4/23/17 4:59 PM, HAA wrote:
> Elizabeth D. Rather wrote:
>> On 4/23/17 2:56 PM, HAA wrote:
>>> Elizabeth D. Rather wrote:
>>>> On 4/23/17 3:55 AM, krishna.myneni@ccreweb.org wrote:
>>>>> On Saturday, April 22, 2017 at 10:02:38 PM UTC-5, HAA wrote:
>>>>> ...
>>>>>> 'Starting Forth' was polyForth where all the MOD words were unsigned.  My guess is
>>>>>> as there was no equivalent of FM/MOD or SM/REM for users to NIP, they provided M/ .
>>>>>
>>>>> Yes, Starting Forth has UM/MOD but no signed equivalent.
>>>>
>>>> That's because no one suggested any likely application scenarios that
>>>> benefit from or require a signed M/MOD. Most of the time when you
>>>> dealing with a MOD you're doing something inherently unsigned.
>>>>
>>>> Cheers,
>>>> Elizabeth
>>>
>>> Hard to believe you've never encountered situations involving a negative
>>> dividend, positive divisor, requiring a positive mod.
>>
>> 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

-- 
Elizabeth D. Rather
FORTH, Inc.
6080 Center Drive, Suite 600
Los Angeles, CA  90045
USA

[toc] | [prev] | [next] | [standalone]


#57954

Fromhughaguilar96@gmail.com
Date2017-04-23 21:22 -0700
Message-ID<48736279-4231-4045-a4bf-1826feeeff4f@googlegroups.com>
In reply to#57951
On Sunday, April 23, 2017 at 9:03:15 PM UTC-7, Elizabeth D. Rather wrote:
> On 4/23/17 4:59 PM, HAA wrote:
> > Elizabeth D. Rather wrote:
> >> On 4/23/17 2:56 PM, HAA wrote:
> >>> Elizabeth D. Rather wrote:
> >>>> On 4/23/17 3:55 AM, krishna.myneni@ccreweb.org wrote:
> >>>>> On Saturday, April 22, 2017 at 10:02:38 PM UTC-5, HAA wrote:
> >>>>> ...
> >>>>>> 'Starting Forth' was polyForth where all the MOD words were unsigned.  My guess is
> >>>>>> as there was no equivalent of FM/MOD or SM/REM for users to NIP, they provided M/ .
> >>>>>
> >>>>> Yes, Starting Forth has UM/MOD but no signed equivalent.
> >>>>
> >>>> That's because no one suggested any likely application scenarios that
> >>>> benefit from or require a signed M/MOD. Most of the time when you
> >>>> dealing with a MOD you're doing something inherently unsigned.
> >>>>
> >>>> Cheers,
> >>>> Elizabeth
> >>>
> >>> Hard to believe you've never encountered situations involving a negative
> >>> dividend, positive divisor, requiring a positive mod.
> >>
> >> 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.

Show us your code! You apparently are an expert on converting numbers into strings --- let us see your wonderful code! --- you are just telling lies again; you don't have any code...

This is my code from the novice-package:
-------------------------------------------------------------------------

\ ******
\ ****** The following is for numeric output.
\ ******

: comma ( d -- d )
    [char] , hold ;

: dot ( d -- d )
    [char] . hold ;

: _# ( d -- d_less_digit )                                      \ digit if number is non-zero, else a blank
    2dup d0= if  bl hold  else  #  then ;

: _comma ( d -- d )                                             \ comma if number is non-zero, else a blank
    2dup d0= if  bl hold  else  comma  then ;

\ _# and _comma are used to blank-out the leftmost of the number if the digits are zero.

: book-sign ( d neg? -- d )
    if  [char] -  else  [char] +  then  hold ;

\ This is a bookkeeping-style sign. It prints a + for positive rather than print nothing.

item ?sgn               \ used by ?# and ?COMMA

: ?# ( d -- new-d )     \ needs ?SGN set        \ similar to _# except puts a - in there if ?SGN is set
    2dup d0= if
        ?sgn if  ?sgn sign  then
        false to ?sgn
    else
        #  then ;

: ?comma ( d -- d )     \ needs ?SGN set        \ similar to _comma except puts a - in there if ?SGN is set
    2dup d0= if
        ?sgn if  ?sgn sign  then
        false to ?sgn
    else
        comma  then ;

: <big.> ( d -- adr cnt )               \ used for big numbers that need commas for clarity
    2dup d0< to ?sgn  dabs
    <#
     # ?# ?#  ?comma
    ?# ?# ?#  ?comma
    ?# ?# ?#  ?comma
    ?# ?# ?#  ?comma
    ?# ?# ?#  ?comma
    ?# ?# ?#  ?comma
    ?#
    #> ;

: big. ( d -- )
    <big.> type ;

item ~#soft                             \ TRUE implies that ~# shouldn't output zeros

: ~# ( Da -- Db )                       \ needs ~#SOFT set
    ~#soft if
        2dup  10 um/mod drop if  #  false to ~#soft
        else  1 10 m*/  then
    else
        #  then ;

: ~. ( D -- D )                         \ needs ~#SOFT set
    ~#soft not if  [char] . hold  then ;

\ ~# is used for the digits to the right of the decimal point.
\ ~. is used for the decimal point.

: round-off { prec -- }                             \ float: n -- new-n
    prec 1 ?do  10.e f*  loop  fnear
    prec 1 ?do  10.e f/  loop ;

: adjust-down ( adjustment -- new-adjustment )      \ float: n -- new-n
    begin  fdup 10.e f>= while
        10.e f/  1+  repeat ;

: adjust-up ( adjustment -- new-adjustment )        \ float: n -- new-n
    begin  fdup 1.e f< while
        10.e f*  1-  repeat ;

: exponent { prec | sgn -- adjustment }             \ float: n -- new-n
    0                           \ -- adjustment
    fdup f0= if  exit then
    fdup f0< to sgn  fabs
    adjust-up
    adjust-down  prec round-off  adjust-down
    sgn if  fnegate  then ;

: #exponent ( n -- )                    \ must be called from within <# #>
    ?dup if
        dup >r  abs 0                   \ -- d
        #s  r> sign  [char] e hold      \ -- d0
        2drop  then ;

: <scientific>  { prec engineering? | sgn exp -- adr cnt }       \ float: n --
    prec 1 < abort" *** F>STRING needs a precision parameter >= 1 ***"
    prec exponent to exp
    engineering? if
        begin  exp 3 mod while  10.e f*  -1 +to exp  -1 +to prec  repeat
        fdup fabs  prec round-off
        1000.e f>= if  1000.e f/  3 +to exp  3 +to prec  then
        then
    prec 1 ?do  10.e f*  loop
    fnear f>d
    dup to sgn  dabs <#  bl hold
    exp #exponent
    true to ~#soft  prec 1 ?do  ~#  loop  ~.
    2dup or if  #s
    else        ~#soft if  #s  then     then
    sgn sign  #> ;

\ The e is optional, which prevents these numbers from being used in Forth source-code.  >FLOAT still works though.

10 constant max-prec    \ 11 works sometimes, but fails if the most significant digit is large.  10 always works.

: scientific ( -- adr cnt )                         \ float: n --
    precision false <scientific> ;

: max-scientific ( -- adr cnt )                     \ float: n --
    max-prec false <scientific> ;

: engineering ( -- adr cnt )                        \ float: n --
    precision true <scientific> ;

: max-engineering ( -- adr cnt )                    \ float: n --
    max-prec true <scientific> ;

2000000001 constant eng-lim                         \ must be a positive integer
\ In <ENG> any float >= the lim goes to ENGINEERING and otherwise is done without an 'e'

: <eng> ( -- adr cnt lim )                          \ float: n --
    fdup fabs  s>d d>f f>=  fdup fabs 1e f<  or if  engineering  exit then
    <cstr
        fdup f0< if  [char] - char+cstr  then
        fabs
        fdup f>d  2dup <big.> <+cstr>
        d>f f-                                      \ float: integer-part
        fdup f0=  0= if
            [char] . char+cstr
            precision 0 ?do  10.e f*  loop
            true to ~#soft
            fround f>d <#  precision 0 ?do ~# loop  #>  <+cstr>
            then
        cstr> count ;

: eng ( -- adr cnt )                                \ float: n --
    eng-lim <eng> ;

: HOLDS ( adr len -- )  \ HOLD a string
   BEGIN DUP WHILE 1- 2DUP CHARS + C@ HOLD REPEAT 2DROP ;

\ HOLDS was written by HAA (he called it $HOLD though): https://groups.google.com/forum/#!topic/comp.lang.forth/ictps0w02yk

[toc] | [prev] | [next] | [standalone]


#58051

From"HAA" <someone@microsoft.com>
Date2017-04-25 12:53 +1000
Message-ID<odmdoe$1ojj$1@gioia.aioe.org>
In reply to#57951
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.


[toc] | [prev] | [next] | [standalone]


#58070

From"Elizabeth D. Rather" <erather@forth.com>
Date2017-04-24 21:55 -1000
Message-ID<EamdnXN2NouenGLFnZ2dnUU7-SGdnZ2d@supernews.com>
In reply to#58051
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

-- 
Elizabeth D. Rather
FORTH, Inc.
6080 Center Drive, Suite 600
Los Angeles, CA  90045
USA

[toc] | [prev] | [next] | [standalone]


#58082

From"HAA" <someone@microsoft.com>
Date2017-04-25 20:00 +1000
Message-ID<odn6ol$snt$1@gioia.aioe.org>
In reply to#58070
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 ! ;




[toc] | [prev] | [standalone]


Page 3 of 3 — ← Prev page 1 2 [3]

Back to top | Article view | comp.lang.forth


csiph-web