On 2023-01-02 10:32:07 Glenn Knickerbocker wrote:
> I don't know how I've never gotten around to making this wish:  Sure
> would be nice to have a method that returned both the integer quotient
> and the remainder without having to do the division twice.  Like this but
> in a single operation:
>
>  x~quotient  = dividend %divisor
>  x~remainder = dividend//divisor
>
> In the program at hand, I'm just factoring, so I only have to divide the
> second time after I've found a factor.  But in cases where you need to
> process a lot of nonzero remainders, it'd be nice not to have to divide
> again to get the quotient.
>
> ¬R
>
>
>
>
> _______________________________________________
> Oorexx-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/oorexx-users


        Something like I've attached?

Leslie
-- 
Platform: Linux
Distribution: openSUSE Leap 15.4 (x86_64)
::class IntDev public

::attribute quotient
::attribute remainder

::method divide
  expose quotient remainder
  use strict arg dividend , divisor

  if dividend ~ datatype(WholeNumber) = .False then
    raise syntax 88.904              -- Must be a whole number.

  if divisor ~ datatype(WholeNumber) = .False -
   | divisor                         = 0      -
  then
    raise syntax 88.905              -- Must be a non-zero whole number.

  quotient  = dividend %  divisor
  remainder = dividend // divisor
return
#!/usr/bin/env rexx
-- Test the IntDev class.
  parse arg iterations .          -- How many tests to perform.

  if iterations ~ length = 0 then
    iterations = 5

  if iterations < 1 then
    exit

  loop iterations
    dividend = random(0, 65535)
    divisor  = random(0, 65535)
    numbers  = .IntDev ~ new

    numbers ~ divide(dividend, divisor)

    say 'Dividend  =' dividend
    say 'Divisor   =' divisor
    say 'Quotient  =' numbers ~ quotient
    say 'Remainder =' numbers ~ remainder
    say
  end
exit

::requires 'IntDev.cls'
_______________________________________________
Oorexx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to