Skip to content

Commit 6eeb67d

Browse files
author
Jon-Patrick Cook
committed
Improved consistency of embedded/function level comments (i.e. removed /* and */ on own line) and code structure spacing for conditionals per PEP 7 - C Style. Removed additional leading "*" characters in multi-line comments.
Consider further addresing redundant parens in return statements per PEP 7, though some may be best for visual grouping.
1 parent fab8ec2 commit 6eeb67d

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

Modules/mathmodule.c

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@ m_remainder(double x, double y)
540540
absy = fabs(y);
541541
m = fmod(absx, absy);
542542

543-
/*
544-
Warning: some subtlety here. What we *want* to know at this point is
543+
/* Warning: some subtlety here. What we *want* to know at this point is
545544
whether the remainder m is less than, equal to, or greater than half
546545
of absy. However, we can't do that comparison directly because we
547546
can't be sure that 0.5*absy is representable (the multiplication
@@ -557,8 +556,7 @@ m_remainder(double x, double y)
557556
- if m < 0.5*absy then either (i) 0.5*absy is exactly representable,
558557
in which case 0.5*absy < absy - m, so 0.5*absy <= c and hence m <
559558
c, or (ii) absy is tiny, either subnormal or in the lowest normal
560-
binade. Then absy - m is exactly representable and again m < c.
561-
*/
559+
binade. Then absy - m is exactly representable and again m < c. */
562560

563561
c = absy - m;
564562
if (m < c) {
@@ -568,8 +566,7 @@ m_remainder(double x, double y)
568566
r = -c;
569567
}
570568
else {
571-
/*
572-
Here absx is exactly halfway between two multiples of absy,
569+
/* Here absx is exactly halfway between two multiples of absy,
573570
and we need to choose the even multiple. x now has the form
574571
575572
absx = n * absy + m
@@ -593,8 +590,7 @@ m_remainder(double x, double y)
593590
594591
Note that all steps in fmod(0.5 * (absx - m), absy)
595592
will be computed exactly, with no rounding error
596-
introduced.
597-
*/
593+
introduced. */
598594
assert(m == c);
599595
r = m - 2.0 * fmod(0.5 * (absx - m), absy);
600596
}
@@ -1423,7 +1419,7 @@ math_fsum(PyObject *module, PyObject *seq)
14231419
if (iter == NULL)
14241420
return NULL;
14251421

1426-
for(;;) { /* for x in iterable */
1422+
for (;;) { /* for x in iterable */
14271423
assert(0 <= n && n <= m);
14281424
assert((m == NUM_PARTIALS && p == ps) ||
14291425
(m > NUM_PARTIALS && p != NULL));
@@ -2450,8 +2446,7 @@ math_fmod_impl(PyObject *module, double x, double y)
24502446
#ifdef _MSC_VER
24512447
/* Windows (e.g. Windows 10 with MSC v.1916) loose sign
24522448
for zero result. But C99+ says: "if y is nonzero, the result
2453-
has the same sign as x".
2454-
*/
2449+
has the same sign as x". */
24552450
if (r == 0.0 && y != 0.0) {
24562451
r = copysign(r, x);
24572452
}
@@ -3088,11 +3083,9 @@ math_pow_impl(PyObject *module, double x, double y)
30883083
if (isnan(r)) {
30893084
errno = EDOM;
30903085
}
3091-
/*
3092-
an infinite result here arises either from:
3086+
/* an infinite result here arises either from:
30933087
(A) (+/-0.)**negative (-> divide-by-zero)
3094-
(B) overflow of x**y with x and y finite
3095-
*/
3088+
(B) overflow of x**y with x and y finite */
30963089
else if (isinf(r)) {
30973090
if (x == 0.)
30983091
errno = EDOM;
@@ -3266,27 +3259,24 @@ math_isclose_impl(PyObject *module, double a, double b, double rel_tol,
32663259
return -1;
32673260
}
32683261

3269-
if ( a == b ) {
3270-
/* short circuit exact equality -- needed to catch two infinities of
3271-
the same sign. And perhaps speeds things up a bit sometimes.
3272-
*/
3262+
if (a == b) {
3263+
/* Short circuit exact equality -- needed to catch two infinities of
3264+
the same sign. And perhaps speeds things up a bit sometimes. */
32733265
return 1;
32743266
}
32753267

32763268
/* This catches the case of two infinities of opposite sign, or
32773269
one infinity and one finite number. Two infinities of opposite
32783270
sign would otherwise have an infinite relative tolerance.
32793271
Two infinities of the same sign are caught by the equality check
3280-
above.
3281-
*/
3272+
above. */
32823273

32833274
if (isinf(a) || isinf(b)) {
32843275
return 0;
32853276
}
32863277

3287-
/* now do the regular computation
3288-
this is essentially the "weak" test from the Boost library
3289-
*/
3278+
/* Now do the regular computation. This is essentially the "weak" test
3279+
from the Boost library. */
32903280

32913281
diff = fabs(b - a);
32923282

@@ -3378,9 +3368,8 @@ math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start)
33783368
Py_INCREF(result);
33793369
#ifndef SLOW_PROD
33803370
/* Fast paths for integers keeping temporary products in C.
3381-
* Assumes all inputs are the same type.
3382-
* If the assumption fails, default to use PyObjects instead.
3383-
*/
3371+
Assumes all inputs are the same type.
3372+
If the assumption fails, default to use PyObjects instead. */
33843373
if (PyLong_CheckExact(result)) {
33853374
int overflow;
33863375
long i_result = PyLong_AsLongAndOverflow(result, &overflow);
@@ -3389,7 +3378,7 @@ math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start)
33893378
Py_SETREF(result, NULL);
33903379
}
33913380
/* Loop over all the items in the iterable until we finish, we overflow
3392-
* or we found a non integer element */
3381+
or we found a non integer element */
33933382
while (result == NULL) {
33943383
item = PyIter_Next(iter);
33953384
if (item == NULL) {
@@ -3409,7 +3398,7 @@ math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start)
34093398
}
34103399
}
34113400
/* Either overflowed or is not an int.
3412-
* Restore real objects and process normally */
3401+
Restore real objects and process normally */
34133402
result = PyLong_FromLong(i_result);
34143403
if (result == NULL) {
34153404
Py_DECREF(item);
@@ -3433,7 +3422,7 @@ math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start)
34333422
if (PyFloat_CheckExact(result)) {
34343423
double f_result = PyFloat_AS_DOUBLE(result);
34353424
Py_SETREF(result, NULL);
3436-
while(result == NULL) {
3425+
while (result == NULL) {
34373426
item = PyIter_Next(iter);
34383427
if (item == NULL) {
34393428
Py_DECREF(iter);
@@ -3476,7 +3465,7 @@ math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start)
34763465
#endif
34773466
/* Consume rest of the iterable (if any) that could not be handled
34783467
by specialized functions above.*/
3479-
for(;;) {
3468+
for (;;) {
34803469
item = PyIter_Next(iter);
34813470
if (item == NULL) {
34823471
/* error, or end-of-sequence */

0 commit comments

Comments
 (0)