« first day (1696 days earlier)      last day (1159 days later) » 

6:31 AM
How should I start to write a C++ program for cos(x) infinite terms . I have to take input x from the user with an accuracy of 5 decimal places.
 
 
4 hours later…
nwp
10:10 AM
@AshKetch You need to be more specific. The answer is int main(int argc, char *argv[]), but that's not very helpful. And then you should be able to just copy a formula from Wikipedia and translate it into C++.
I'm not sure what you mean with the accuracy. 5 decimal places is like 17 bits and a double gives you 52 bits, so that should be plenty. Though I'm not sure which, if any, of the formulas are numerically stable.
 
10:33 AM
I kind of don't get the point of constexpr. Can't const tell by itself if something is a compile time constant and make an optimization if it is? In other words are you really telling me the compiler is too dumb to know the difference between
const auto x = 5;
and
cin >> x;
const auto y = x;
 
nwp
For variables it doesn't really matter. For functions it's more relevant.
 
 
6 hours later…
4:46 PM
@nwp It sort of can. In fact, there are even cases where constexpr const ... make sense (e.g., constexpr const char *foo = "1234"; is not redundant).
The trick to reading this is that constexpr always applies to the object being declared/defined, where (in this case) the const applies to what the pointer refers to. So it's sort of on the same order as: char const * const foo = "1234";
 
4:59 PM
@JerryCoffin to make it more fun constexpr can actually increase memory usage with const items if they are supposed to be shared across TUs. There is in fact an entire tool the chromium team has developed to figure out which one you should use for static data so it always ends up in a read only data page.
 
@Mgetz Ah, the tangled webs we weave...
 
@JerryCoffin it apparently gets quite nasty where they have tricks for data that needs to be available to functions that are intended for consteval
but they consider making sure that all static data is shared a super high priority as it massively reduced chrome's footprint
 
 
2 hours later…
6:34 PM
@Mgetz I can't imagine why they'd care about that. I mean, Chrome hardly ever uses more than a couple terabytes of RAM. Six or eight terabytes at very most (well, unless you open a second tab, of course, but nobody would be crazy enough to open more than one tab at a time, would they?
@nwp Just for what it's worth: double only stores 52 bits, but due to normalization, it effectively has 53 bits (except for subnormals).
 

« first day (1696 days earlier)      last day (1159 days later) »