All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wilken Gottwalt <wilken.gottwalt@posteo.net>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Hardware Monitoring <linux-hwmon@vger.kernel.org>,
	Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH v2] hwmon: (corsair-psu) Fix linear11 calculation
Date: Thu, 06 Aug 2026 16:42:35 +0000	[thread overview]
Message-ID: <20260806184233.44124904@posteo.net> (raw)
In-Reply-To: <f4077f39-0427-4bb9-8b6c-ddba3f492765@roeck-us.net>

On Thu, 6 Aug 2026 09:28:34 -0700
Guenter Roeck <linux@roeck-us.net> wrote:

> On 8/6/26 08:56, Wilken Gottwalt wrote:
> ...
> >>>> +	s64 result = mant * scale;
> >>>
> >>> Uhm, this is a 32bit multiplicaiton, actully a C gotcha I explain the beginners
> >>> in our company. https://godbolt.org/z/eM6TbGG5E
> >>>
> >>
> >> It is, but that is ok and intentional: both mant and exp are guaranteed to be
> >> no larger than s16, meaning the result is never larger than s32 and will never
> >> overflow.
> >>
> >>>> -	return (exp >= 0) ? (result << exp) : (result >> -exp);
> >>>> +	if (exp >= 0)
> >>>> +		result *= (int)(1UL << exp);
> >>
> >> This is the calculation that can overflow, making it necessary for result to be s64.
> > 
> > Yeah, it was just funny to see in the wild. It made my day. :D
> > 
> 
> Guess I lost you there. Do you want me to change it ? I could add a comment, or just
> type cast mant to s64. Please let me know.

No no, it is fine. I just was surprised to see that famous gotcha. But I guess
some AIs may jump on it, ignoring the context. Changing it maybe would prevent
noise in the future. It is like that famous mathematical "iff" term, which is
used in some places of the kernel. A lot of non-native English speakers report
that as a typo. Ahh... just ignore my gibberish.

greetings,
Wilken

  reply	other threads:[~2026-08-06 16:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04  3:48 [PATCH v2] hwmon: (corsair-psu) Fix linear11 calculation Guenter Roeck
2026-08-04  3:55 ` sashiko-bot
2026-08-06 15:34 ` Wilken Gottwalt
2026-08-06 15:52   ` Guenter Roeck
2026-08-06 15:56     ` Wilken Gottwalt
2026-08-06 16:28       ` Guenter Roeck
2026-08-06 16:42         ` Wilken Gottwalt [this message]
2026-08-06 18:04           ` Guenter Roeck
2026-08-06 18:28             ` Wilken Gottwalt
2026-08-06 19:15               ` Guenter Roeck
2026-08-07  4:26 ` Wilken Gottwalt
2026-08-07  5:36   ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260806184233.44124904@posteo.net \
    --to=wilken.gottwalt@posteo.net \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=sashiko-bot@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.