<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 557: TR1: div(_Longlong, _Longlong) vs div(intmax_t, intmax_t)</title>
<meta property="og:title" content="Issue 557: TR1: div(_Longlong, _Longlong) vs div(intmax_t, intmax_t)">
<meta property="og:description" content="C++ library issue. Status: NAD Editorial">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue557.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#NAD_Editorial">NAD Editorial</a> status.</em></p>
<h3 id="557"><a href="lwg-closed.html#557">557</a>. TR1: div(_Longlong, _Longlong) vs div(intmax_t, intmax_t)</h3>
<p><b>Section:</b> 17.4.1 <a href="https://wg21.link/cstdint.syn">[cstdint.syn]</a>, 99 [tr.c99.cstdint] <b>Status:</b> <a href="lwg-active.html#NAD_Editorial">NAD Editorial</a>
 <b>Submitter:</b> Paolo Carlini <b>Opened:</b> 2006-02-06 <b>Last modified:</b> 2023-02-07</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#cstdint.syn">issues</a> in [cstdint.syn].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD Editorial">NAD Editorial</a> status.</p>
<p><b>Discussion:</b></p>
<p>
I'm seeing a problem with such overloads: when, _Longlong == intmax_t ==
long long we end up, essentially, with the same arguments and different
return types (lldiv_t and imaxdiv_t, respectively). Similar issue with
abs(_Longlong) and abs(intmax_t), of course.
</p>
<p>
Comparing sections 8.25 and 8.11, I see an important difference,
however: 8.25.3 and 8.25.4 carefully describe div and abs for _Longlong
types (rightfully, because not moved over directly from C99), whereas
there is no equivalent in 8.11: the abs and div overloads for intmax_t
types appear only in the synopsis and are not described anywhere, in
particular no mention in 8.11.2 (at variance with 8.25.2).
</p>
<p>
I'm wondering whether we really, really, want div and abs for intmax_t...
</p>



<p id="res-557"><b>Proposed resolution:</b></p>



<p><i>[
Portland: no consensus.
]</i></p>


<p><b>Rationale:</b></p>
<p><i>[
Batavia, Bill: The <code>&lt;cstdint&gt;</code> synopsis in  [tr.c99.cinttypes.syn] contains:
]</i></p>

<blockquote><pre>
intmax_t imaxabs(intmax_t i);
intmax_t abs(intmax_t i);

imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
imaxdiv_t div(intmax_t numer, intmax_t denom);
</pre></blockquote>

<p><i>[
and in  [tr.c99.cinttypes.def]:
]</i></p>


<blockquote><p>
The header defines all functions, types, and macros the same as C99
subclause 7.8.
</p></blockquote>

<p><i>[
This is as much definition as we give for most other C99 functions,
so nothing need change. We might, however, choose to add the footnote:
]</i></p>


<blockquote><p>
[<i>Note:</i> These overloads for <code>abs</code> and <code>div</code> may well be equivalent to
those that take <code>long long</code> arguments. If so, the implementation is
responsible for avoiding conflicting declarations. -- <i>end note</i>]
</p></blockquote>

<p><i>[
Bellevue: NAD Editorial. Pete must add a footnote, as described below.
]</i></p>


<blockquote>
<p><i>[
Looks like a real problem. Dietmar suggests div() return a template
type. Matt: looks like imaxdiv_t is loosly defined. Can it be a typedef
for lldiv_t when _Longlong == intmax_t? PJP seems to agree. We would
need a non-normative note declaring that the types lldiv_t and imaxdiv_t
may not be unique if intmax_t==_longlong.
]</i></p>

</blockquote>






</body>
</html>
