Skip to content

Commit

Permalink
chore: use iwyu on math/**.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
realstealthninja committed Sep 13, 2024
1 parent c3897d3 commit c47117c
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 88 deletions.
9 changes: 4 additions & 5 deletions math/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
* @author [Focusucof](https://github.com/Focusucof)
*/
#define _USE_MATH_DEFINES
#include <cassert> /// for assert
#include <cmath> /// for M_PI definition and pow()
#include <cmath>
#include <cstdint> /// for uint16_t datatype
#include <iostream> /// for IO operations
#include <cassert> // for assert
#include <cmath> // for NAN, M_PI, pow
#include <cstdint> // for uint16_t
#include <iostream> // for basic_ostream, operator<<, char_traits, endl, cout

/**
* @namespace math
Expand Down
5 changes: 3 additions & 2 deletions math/check_prime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* @author [ewd00010](https://github.com/ewd00010)
*/

#include <cassert> /// for assert
#include <iostream> /// for IO operations
#include <stdint.h> // for int64_t
#include <cassert> // for assert
#include <iostream> // for char_traits, basic_ostream, operator<<, cout, endl

/**
* @brief Mathematical algorithms
Expand Down
13 changes: 7 additions & 6 deletions math/complex_numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
* operators overloaded to accommodate (mathematical) field operations.
*/

#include <cassert>
#include <cmath>
#include <complex>
#include <ctime>
#include <iostream>
#include <stdexcept>
#include <cassert> // for assert
#include <cmath> // for atan2, cos, sin, sqrt
#include <complex> // for complex, abs, arg, conj, operator*, operator+
#include <ctime> // for time
#include <iostream> // for basic_ostream, operator<<, char_traits, cout, endl
#include <stdexcept> // for invalid_argument
#include <cstdlib> // for rand, srand

/**
* \brief Class Complex to represent complex numbers as a field.
Expand Down
12 changes: 7 additions & 5 deletions math/eratosthenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
* @author [Keval Kapdee](https://github.com/thechubbypanda)
*/

#include <cassert> /// For assert
#include <chrono> /// For timing the sieve
#include <iostream> /// For IO operations
#include <string> /// For string handling
#include <vector> /// For std::vector
#include <bits/chrono.h> // for duration, duration_cast, high_resolution_clock
#include <stdint.h> // for uint64_t
#include <cassert> // for assert
#include <iostream> // for basic_ostream, operator<<, cout, endl
#include <string> // for char_traits, basic_string, operator==, string
#include <vector> // for vector
#include <ratio> // for ratio

/**
* @namespace math
Expand Down
6 changes: 3 additions & 3 deletions math/extended_euclid_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* multiplicative inverse of a number. (A * B)%M == 1 Here B is the MMI of A for
* given M, so extendedEuclid (A, M) gives B.
*/
#include <algorithm> // for swap function
#include <iostream>
#include <cstdint>
#include <iostream> // for char_traits, basic_ostream, basic_ostream::opera...
#include <cstdint> // for uint32_t, int32_t
#include <utility> // for swap

/**
* function to update the coefficients per iteration
Expand Down
8 changes: 5 additions & 3 deletions math/factorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
* @author [Akshay Gupta](https://github.com/Akshay1910)
*/

#include <cassert> /// for assert
#include <cstdint> /// for integral typedefs
#include <iostream> /// for I/O operations
#include <cassert> // for assert
#include <cstdint> // for uint64_t, uint8_t
#include <iostream> // for operator<<, basic_ostream, cout
#include <stdexcept> // for invalid_argument

/**
* @namespace
* @brief Mathematical algorithms
Expand Down
5 changes: 2 additions & 3 deletions math/fibonacci_fast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
* @see fibonacci_large.cpp, fibonacci.cpp, string_fibonacci.cpp
*/

#include <cinttypes>
#include <cstdio>
#include <iostream>
#include <cinttypes> // for uint64_t
#include <iostream> // for char_traits, basic_ostream, operator<<, cerr, cout

/**
* maximum number that can be computed - The result after 93 cannot be stored
Expand Down
9 changes: 5 additions & 4 deletions math/fibonacci_large.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
* @see fibonacci.cpp, fibonacci_fast.cpp, string_fibonacci.cpp
*/

#include <cinttypes>
#include <ctime>
#include <iostream>
#include <stdlib.h> // for strtoull
#include <cinttypes> // for uint64_t
#include <ctime> // for clock, clock_t, CLOCKS_PER_SEC, NULL
#include <iostream> // for basic_ostream, char_traits, operator<<

#include "./large_number.h"
#include "./large_number.h" // for large_number, operator<<, operator==

/** Compute fibonacci numbers using the relation
* \f[f(n)=f(n-1)+f(n-2)\f]
Expand Down
3 changes: 2 additions & 1 deletion math/gcd_recursive_euclidean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*
* @see gcd_iterative_euclidean.cpp, gcd_of_n_numbers.cpp
*/
#include <iostream>
#include <iostream> // for basic_ostream, char_traits, operator<<, basic_o...
#include <stdexcept> // for domain_error

/**
* algorithm
Expand Down
15 changes: 8 additions & 7 deletions math/integral_approximation2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
*/

#define _USE_MATH_DEFINES /// for M_PI on windows
#include <cmath> /// for math functions
#include <cstdint> /// for fixed size data types
#include <ctime> /// for time to initialize rng
#include <functional> /// for function pointers
#include <iostream> /// for std::cout
#include <random> /// for random number generation
#include <vector> /// for std::vector
#include <cmath> // for exp, M_PI, sin, sqrt
#include <cstdint> // for uint32_t
#include <ctime> // for time
#include <functional> // for function
#include <iostream> // for basic_ostream, char_traits, operator<<, endl
#include <random> // for normal_distribution, uniform_real_distribution
#include <vector> // for vector
#include <algorithm> // for min

/**
* @namespace math
Expand Down
11 changes: 6 additions & 5 deletions math/inv_sqrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
* This algorithm is used to calculate shadows in Quake III Arena.
*/

#include <cassert> /// for assert
#include <cmath> /// for `std::sqrt`
#include <cstdint> /// for integral typedefs
#include <iostream> /// for IO operations
#include <limits> /// for numeric_limits
#include <cassert> // for assert
#include <cmath> // for fabs, sqrt
#include <cstdint> // for int32_t, int64_t
#include <iostream> // for basic_ostream, char_traits, operator<<, cout
#include <type_traits> // for conditional

/**
* @brief This is the function that calculates the fast inverse square root.
* The following code is the fast inverse square root implementation from
Expand Down
8 changes: 4 additions & 4 deletions math/iterative_factorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
*
*/

#include <cassert> /// for assert
#include <cstdint> /// for integral types
#include <exception> /// for std::invalid_argument
#include <iostream> /// for std::cout
#include <cassert> // for assert
#include <cstdint> // for uint64_t, uint8_t
#include <iostream> // for operator<<, basic_ostream, cout
#include <stdexcept> // for invalid_argument

/**
* @namespace
Expand Down
9 changes: 5 additions & 4 deletions math/large_factorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
* \author [Krishna Vedala](https://github.com/kvedala)
* @see factorial.cpp
*/
#include <cstring>
#include <ctime>
#include <iostream>
#include <stdlib.h> // for atoi
#include <cstring> // for strlen, size_t
#include <ctime> // for clock, clock_t, CLOCKS_PER_SEC
#include <iostream> // for basic_ostream, char_traits, operator<<

#include "./large_number.h"
#include "./large_number.h" // for large_number, operator<<

/** Test implementation for 10! Result must be 3628800.
* @returns True if test pass else False
Expand Down
7 changes: 3 additions & 4 deletions math/linear_recurrence_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
* here](https://en.wikipedia.org/wiki/Exponentiation_by_squaring).
* @author [Ashish Daulatabad](https://github.com/AshishYUO)
*/
#include <cassert> /// for assert
#include <cstdint> /// for integral typedefs
#include <iostream> /// for IO operations
#include <vector> /// for std::vector STL
#include <cassert> // for assert
#include <cstdint> // for int64_t, uint32_t, uint64_t
#include <vector> // for vector

/**
* @namespace math
Expand Down
4 changes: 2 additions & 2 deletions math/modular_inverse_fermat_little_theorem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
* (as \f$a\times a^{-1} = 1\f$)
*/

#include <iostream>
#include <vector>
#include <stdint.h> // for int64_t
#include <iostream> // for char_traits, basic_ostream, operator<<, cout, endl

/** Recursive function to calculate exponent in \f$O(\log n)\f$ using binary
* exponent.
Expand Down
10 changes: 6 additions & 4 deletions math/n_bonacci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
* @author [Swastika Gupta](https://github.com/Swastyy)
*/

#include <cassert> /// for assert
#include <cstdint> /// for integral typedefs
#include <iostream> /// for std::cout
#include <vector> /// for std::vector
#include <cassert> // for assert
#include <cstdint> // for uint64_t
#include <iostream> // for char_traits, basic_ostream, operator<<
#include <vector> // for vector, operator==
#include <initializer_list> // for initializer_list

/**
* @namespace math
* @brief Mathematical algorithms
Expand Down
7 changes: 4 additions & 3 deletions math/ncr_modulo_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* @author [Kaustubh Damania](https://github.com/KaustubhDamania)
*/

#include <cassert> /// for assert
#include <iostream> /// for std::cout
#include <vector> /// for std::vector
#include <stdint.h> // for int64_t
#include <cassert> // for assert
#include <iostream> // for char_traits, basic_ostream, operator<<, basic_os...
#include <vector> // for vector

/**
* @namespace math
Expand Down
8 changes: 4 additions & 4 deletions math/prime_factorization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file
* @brief Prime factorization of positive integers
*/
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cstring> // for memset
#include <iostream> // for char_traits, basic_ostream, operator<<, basic_os...
#include <vector> // for vector
#include <utility> // for pair, make_pair

/** Declaring variables for maintaing prime numbers and to check whether a
* number is prime or not
Expand Down
5 changes: 3 additions & 2 deletions math/prime_numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* @brief Get list of prime numbers
* @see primes_up_to_billion.cpp sieve_of_eratosthenes.cpp
*/
#include <iostream>
#include <vector>
#include <cstddef> // for size_t
#include <iostream> // for char_traits, basic_ostream, operator<<, cout
#include <vector> // for vector

/** Generate an increasingly large number of primes
* and store in a list
Expand Down
5 changes: 3 additions & 2 deletions math/primes_up_to_billion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* @brief Compute prime numbers upto 1 billion
* @see prime_numbers.cpp sieve_of_eratosthenes.cpp
*/
#include <cstring>
#include <iostream>
#include <stdint.h> // for int64_t
#include <cstring> // for memset
#include <iostream> // for operator<<, basic_ostream, cout, basic_istream, cin

/** array to store the primes */
char prime[100000000];
Expand Down
16 changes: 8 additions & 8 deletions math/quadratic_equations_complex_numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
* (-0.5,0.866025) (-0.5,0.866025)
*/

#include <array> /// std::array
#include <cassert> /// assert
#include <cmath> /// std::sqrt, std::trunc, std::pow
#include <complex> /// std::complex
#include <exception> /// std::invalid_argument
#include <iomanip> /// std::setprecision
#include <iostream> /// std::cout
#include <array> // for array, operator==
#include <cassert> // for assert
#include <cmath> // for round, sqrt, pow
#include <complex> // for complex, operator==
#include <cstddef> // for size_t
#include <iostream> // for operator<<, basic_ostream, cout
#include <stdexcept> // for invalid_argument

/**
* @namespace
Expand Down Expand Up @@ -65,7 +65,7 @@ std::array<std::complex<long double>, 2> quadraticEquation(long double a,
solutions[1] = -b * 0.5 / a;
return solutions;
}

// Complex root (discriminant < 0)
// Note that the left term (-b / 2a) is always real. The imaginary part
// appears when b^2 - 4ac < 0, so sqrt(b^2 - 4ac) has no real roots. So,
Expand Down
7 changes: 4 additions & 3 deletions math/realtime_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
* simple enough to be easily implemented in an embedded system.
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#include <cassert>
#include <cmath>
#include <iostream>
#include <bits/std_abs.h> // for abs
#include <cassert> // for assert
#include <cmath> // for sqrt
#include <iostream> // for basic_ostream, char_traits, operator<<, cout

/**
* \namespace statistics
Expand Down
8 changes: 4 additions & 4 deletions math/string_fibonacci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* @see fibonacci_large.cpp, fibonacci_fast.cpp, fibonacci.cpp
*/

#include <cstdint> /// for integral typedefs
#include <iostream>
#include <cstdint> // for uint64_t
#include <iostream> // for char_traits, basic_ostream, operator<<, cout
#include <string> // for allocator, basic_string, operator+, string, oper...
#ifdef _MSC_VER
#include <string> // use this for MS Visual C
#include <string> // for allocator, basic_string, operator+, string, oper...
#else
#include <cstring> // otherwise
#endif

/**
Expand Down

0 comments on commit c47117c

Please sign in to comment.