help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can Bash do simple math?


From: alex xmb sw ratchev
Subject: Re: Can Bash do simple math?
Date: Tue, 6 Aug 2024 19:57:42 +0200

On Tue, Aug 6, 2024, 19:52 Greg Wooledge <greg@wooledge.org> wrote:

> On Tue, Aug 06, 2024 at 19:07:29 +0200, bash@blaklinten.xyz wrote:
> > On Tue, Aug 06, 2024 at 06:24:13PM +0200, alex xmb sw ratchev wrote:
> > > i say users code has
> > > seconds = diffinseconds % 60
> > > not
> > > minutes = diffinseconds % 60
> > >
> > diff_in_seconds % 60 gives the seconds portion of diff_in_seconds.
> > i.e. diff_in_seconds = 54 -> 54 % 60 = 54.
> >      diff_in_seconds = 325 -> 325 % 60 = 25.
>
> I think he simply doesn't know what the % operator does.
>
> The % operator performs a "modulus" operation, which is just a fancy
> word for "the remainder after performing an integer division".
>
> In the second example above, 325 % 60 means "divide 325 by 60, and throw
> away the quotient, but keep the remainder".  60 goes into 325 5 times
> (because 60 * 5 = 300), and the remainder is 25.
>
> Therefore, 325 % 60 = 25.
>
> If the duration is 325 seconds, then the converted interval is 5 minutes
> and 25 seconds.  In this case, when we divided 325 by 60, 5 was the
> quotient, and 25 was the remainder.  For a conversion to minutes and
> seconds (not hours), that's all you need to do.
>

i think i get it
but thats nonsense , to base 60 on 1sec

its like a scala
like / 50 , just 60
..

where is base ( beginning number ) not in_seconds
its like a non 100 or 50 scale , 60
no raw seconds

sry

>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]