> On 22.6.2026 01:07 CEST Morgan <[email protected]> wrote:
> 
>  
> On 2026-06-22 01:57, Tim Düsterhus wrote:
> > Hi
> > 
> > Operation-wise I would agree that “div mod” is the correct thing to do, 
> > but I don't think that calling Duration/Duration->(int, Duration) 
> > literally divmod is an intuitive API when there's also the other 
> > division that does Duration/int->Duration.
> > 
> > Best regards
> > Tim Düsterhus
> 
> 
> Oof. Naming.
> The only term I can find that is specifically about dividing one 
> duration by another is "beat", but that's definitely domain-specific.
> 
> 'periodCount' or 'countPeriods' come to mind. Since in 'n/d' we're 
> counting how many times duration 'd' occurs during duration 'n' we're 
> basically multiplying the duration by frequency '1/d'; the inverse of 
> the frequency - 'd' itself - is called the period. Which word is also 
> used for "named subdivision of historical time", "class-sized 
> subdivision of a school day", and so on.
> 
> The biggest hangup with that name is that it doesn't explicitly state 
> that it returns the remainder as well. periodParts? periodDivide?

I would go with `divideBy(int|float|self $divisor): self|int|float` where the 
argument type defines the return type:
* `divideBy(int|float $divisor): self`
* `divideBy(self $divisor): int|float`

Together with a modulo operator method (not needed as first MVP) 
`moduloBy(int|float|self $divisor): self`:
* `THIS(duration) modulo OTHER(duration)`: What is the rest of the integer 
division of this duration by another duration?
  - e.g. `5.5s mod 1.2s = 0.7s` as 1.2s fits 4 times into 5.5s and 0.7s is the 
remainder.
* `THIS(duration) modulo NUMBER`: What is the remainder after dividing this 
duration into pieces?
  - e.g. `5.5s mod 750 = 250ns` as 5.5s divided into 750 pieces gives you 
7,333,333ns for each piece with a reminder of 250ns. Means `5.5s = 750 * 
7333333ns + 250ns`.

About integer division - I don't think this is the usual case so I would keep 
that separate (for later) just like `$int / $int = int|float` is the usual case 
and integer division `intdiv(): int` needs to be handled more explicitly is 
needed.

Regards,
Marc

Reply via email to