cot(x) = cos(x)/sin(x)
should be more numerically stable close to π/2 than cot(x) = 1/tan(x)
. You can implement that efficiently using sincos
on platforms that have it.
Another possibility is cot(x) = tan(M_PI_2 - x)
. This should be faster than the above (even if sincos
is available), but it may also be less accurate, because M_PI_2
is of course only an approximation of the transcendental number π/2, so the difference M_PI_2 - x
will not be accurate to the full width of a double
mantissa — in fact, if you get unlucky, it may have only a few meaningful bits.
Related Posts:
- How to use the PI constant in C++
- Pause Console in C++ program
- Why the switch statement cannot be applied on strings?
- ld: symbol(s) not found for architecture x86_64 error
- C++ string to double conversion
- How do I print out the contents of a vector?
- ‘was not declared in this scope’ error
- Good input validation loop using cin – C++
- C++ for each, pulling from vector elements
- How do I erase an element from std::vector<> by index?
- Incomplete Type Is Not Allowed
- how to implement quick sort algorithm in C++
- Why use ‘glad’ library for opengl initialization? [duplicate]
- What does `*&` in a function declaration mean?
- (->) arrow operator and (.) dot operator , class pointer
- How to reverse an std::string? [duplicate]
- What is the C version of RMI
- Difference between ‘strcpy’ and ‘strcpy_s’?
- What is uintptr_t data type
- const int = int const?
- Undefined reference to vtable
- In C++, what is a virtual base class?
- wntdll.pdb not loaded – Can’t see the exception
- What is the difference between a static and const variable?
- What is move semantics?
- unsigned int vs. size_t
- error: expected primary-expression before ‘)’ token (C)
- What does -> mean in C++?
- How to pass optional arguments to a method in C++?
- How to copy a string of std::string type in C++?
- C++ forbids converting a `string` constant to `char*` – Alphabets to Morse converting program
- C++ #include guards
- Is std::stoi actually safe to use?
- C++ forbids variable-size array
- Fill array with random numbers within a specified range (C++)
- Remove an array element and shift the remaining ones
- Right way to split an std::string into a vector
- string subscript out of range error
- push_back vs emplace_back
- No operator << matches these operands
- Returning an empty string : efficient way in c++
- How to find the size of an int[]?
- Append an int to a std::string
- Decimal to hex conversion c++ built-in function
- C++ IDE with repl?
- error: use of deleted function
- Run C++ in command prompt – Windows
- expected unqualified-id before string constant
- C++: Access violation writing location
- error: strcpy was not declared in this scope
- how to print a string to console in c++
- How to call a parent class function from derived class function?
- Error: No instance of constructor matches the argument list
- How can I get the list of files in a directory using C or C++?
- RPN Calculator for C++
- What does `Fatal Python error: PyThreadState_Get: no current thread` mean?
- Debug Assertion Failed: _CrtIsValidHeapPointer(block)
- gdb error not in executable format: File format not recognized
- C++ Erase vector element by value rather than by position?
- C++ Class ‘undeclared identifier”
- Destructor for Binary Search Tree
- What is the most popular general purpose C++ framework?
- Adding message to assert
- c++ error: invalid types ‘int[int]’ for array subscript
- C++ – include unistd.h: why not cunistd?
- Dynamically allocated string array, then change it’s value?
- Use the auto keyword in C++ STL
- c++ –
- C++ – statement cannot resolve address for overloaded function
- What’s the difference between * and & in C?
- is there is a compiler which convert c++ code into mips assembly language
- term does not evaluate to a function taking 1 arguments
- reading from stdin in c++
- Difference between pic Vs pie
- C++ Templates – LinkedList
- stoi function gives error: std::invalid_argument at memory location 0x0035E8D8. c++
- Stack around the variable ‘ ‘ was corrupted
- The difference between cin.ignore and cin.sync
- casting int to char using C++ style casting
- How to print (using cout) a number in binary form?
- What is the job of autogen.sh when building a c++ package on Linux
- Using G++ to compile multiple .cpp and .h files
- LPCSTR, LPCTSTR and LPTSTR
- How to do std::string indexof in C++ that returns index of matching string?
- variable or field declared void
- Invalid conversion from ‘char’ to ‘const char *’
- How do I deal with “signed/unsigned mismatch” warnings (C4018)?
- Creating folders in C++
- Modulo operator with negative values [duplicate]
- Finding the type of an object in C++
- C++ Simple Dice roll – how to return multiple different random numbers [duplicate]
- How can I get a file’s size in C++?
- Why can’t I make a vector of references?
- What does “-Wall” in “g++ -Wall test.cpp -o test” do?
- C++ equivalent of StringBuffer/StringBuilder?
- heap corruption detected | C++
- Update g++ but still old version
- module unsafe for SAFESEH image C++
- Why are there two different getline() functions (if indeed there are)?
- no matching function to call for “getline”