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


Groups > comp.lang.forth > #55983

Re: n00b confusion regarding the implementation vs. specification of *

Subject Re: n00b confusion regarding the implementation vs. specification of *
References (2 earlier) <oan2oo$re9$3@dont-email.me> <7-Kdnc0K7-nnBVLFnZ2dnUU7-e-dnZ2d@supernews.com> <oaocaq$659$1@dont-email.me> <fv-dnWWowP15TVLFnZ2dnUU7-WXNnZ2d@supernews.com> <oapk4c$rft$1@dont-email.me>
Newsgroups comp.lang.forth
From "Elizabeth D. Rather" <erather@forth.com>
Organization FORTH, Inc.
Date 2017-03-20 14:40 -1000
Message-ID <HMKdnUdF0ODq603FnZ2dnUU7-R_NnZ2d@supernews.com> (permalink)

Show all headers | View raw


On 3/20/17 12:15 PM, rickman wrote:
> On 3/20/2017 8:53 AM, Andrew Haley wrote:
>> rickman <gnuarm@gmail.com> wrote:
>>> On 3/20/2017 4:53 AM, Andrew Haley wrote:
>>>> rickman <gnuarm@gmail.com> wrote:
>>>>> On 3/19/2017 2:58 PM, Andrew Haley wrote:
>>>>>>
>>>>>> In two's complement representation, for every pair of arguments,
>>>>>> signed or unsigned, the resulting bit pattern is correct when
>>>>>> interpreted as either signed or unsigned.  This follows because
>>>>>> signed and unsigned addition don't need special handling, and
>>>>>> multiplication is no more than repeated addition.
>>>>>
>>>>> Try it sometime.  A multiplication routine doing shift and add of the
>>>>> multiplicand using the bits in the multiplier as enable flags does not
>>>>> work for a negative multiplier.  If your statement were correct, it
>>>>> should work regardless.  Instead the multiplier has to be negated
>>>>> along
>>>>> with the result.
>>>>
>>>> Please provide an example of a pair of numbers which demonstrates
>>>> this.
>>>
>>> Any non-trivial negative number for a multiplier.  Try it, you'll see.
>>> I wracked my brain trying to figure out a way to adjust the result to
>>> make it work.  After all, negative numbers just have the sign bit
>>> different, right?  Good luck!
>>>
>>> Albert, indicated that multiply works the same for unsigned and signed
>>> numbers as long as the unsigned numbers don't overflow.  However if you
>>> do a signed multiply using an unsigned number with the msb set, that
>>> screws it up.  This is true even if the result is double precision.  So
>>> you can't do an unsigned multiply on signed numbers in the general case.
>>>
>>>   0101  (5)  multiplicand
>>> x 1010  (-6) multiplier
>>
>> The result is -30, which does not fit in a 4-bit signed integer.
>
> So?  A multiply operation in general produces as many bits in the result
> as the total number of bits in the operands.  You can always toss any
> bits you choose, but that is not inherent in the multiply in any way.
>
>
>> The question is about the Forth word *, which by definition takes two
>> cell-size numbers and multiplies them together, producing a product of
>> cell size.  The question is not about any other definition of
>> multiplication, especially not one which has a double-length product.
>>
>> Mixed-precision multiplication needs M* and UM*, obviously.
>
> Ok, if you limit multiplication to results that fit in the same word as
> the operands signed and unsigned may be the same.

All of this points up why some of Forth's unique arithmetic operators 
are so valuable, such as M*/ which multiplies two singles giving a 
double-length product, which is then divided by a single. This takes 
advantage of the fact that MUL operators on virtually all processors 
leave a DP product, and DIV operators divide a double by a single, so 
combining these into one mixed operator gives you a more precise result 
in many cases than using * followed by /.

Cheers,
Elizabeth

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

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


Thread

n00b confusion regarding the implementation vs. specification of * Michael Barry <barrym95838@yahoo.com> - 2017-03-19 10:41 -0700
  Re: n00b confusion regarding the implementation vs. specification of * Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-03-19 13:58 -0500
    Re: n00b confusion regarding the implementation vs. specification of * rickman <gnuarm@gmail.com> - 2017-03-19 19:06 -0400
      Re: n00b confusion regarding the implementation vs. specification of * Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-03-20 03:53 -0500
        Re: n00b confusion regarding the implementation vs. specification of * rickman <gnuarm@gmail.com> - 2017-03-20 06:56 -0400
          Re: n00b confusion regarding the implementation vs. specification of * Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-03-20 07:53 -0500
            Re: n00b confusion regarding the implementation vs. specification of * rickman <gnuarm@gmail.com> - 2017-03-20 18:15 -0400
              Re: n00b confusion regarding the implementation vs. specification of * Coos Haak <htrofhc@gmail.com> - 2017-03-20 23:30 +0100
              Re: n00b confusion regarding the implementation vs. specification of * julian.fondren@endurance.com - 2017-03-20 15:34 -0700
              Re: n00b confusion regarding the implementation vs. specification of * "Elizabeth D. Rather" <erather@forth.com> - 2017-03-20 14:40 -1000
                Re: n00b confusion regarding the implementation vs. specification of * hughaguilar96@gmail.com - 2017-03-20 19:41 -0700
                Re: n00b confusion regarding the implementation vs. specification of * anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-21 17:18 +0000
          Re: n00b confusion regarding the implementation vs. specification of * anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-20 15:07 +0000
  Re: n00b confusion regarding the implementation vs. specification of * hughaguilar96@gmail.com - 2017-03-19 12:32 -0700
    Re: n00b confusion regarding the implementation vs. specification of * hughaguilar96@gmail.com - 2017-03-19 13:54 -0700
  Re: n00b confusion regarding the implementation vs. specification of * albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-03-19 21:21 +0100
    Re: n00b confusion regarding the implementation vs. specification of * Michael Barry <barrym95838@yahoo.com> - 2017-03-19 16:41 -0700
      Re: n00b confusion regarding the implementation vs. specification of * anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-21 17:56 +0000
  Re: n00b confusion regarding the implementation vs. specification of * anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-20 08:57 +0000

csiph-web