« first day (1655 days earlier)      last day (1200 days later) » 

2:05 AM
Can I directly compare (double)3.0 with (int)3? Is there any potential problem that I should be aware of?
 
 
2 hours later…
3:38 AM
@John If you try to compare them, the int will be converted to double, then the two doubles compared to each other. Potential problems...one possibility (but pretty unlikely with int) is that when the int is converted to double, the value changes. That's unlikely with int as such (which is typically 32 bits); a lot more likely with long long, which is 64 bits (so it can represent values a double can't).
 
 
3 hours later…
6:12 AM
@JerryCoffin I see. Thank you.
 
6:31 AM
Surely.
 
I remember that my teacher told me to pay attention to +0.0 and -0.0.
 
@John Most modern hardware will automatically compensate, so +0 and -0 will compare equal. The last time I dealt with anything that needed the user to get involved was on a Control Data mainframe (which were obsolete by the mid-1980's or so). Their FORTRAN compiler automatically inserted code to deal with +0 and -0 in comparisons. Their Pascal compiler converted -0 to +0 immediately.
The only time you had to get involved was if you wrote a subroutine in FORTRAN, and called it from Pascal, in which case you added 0.0 to each operand before doing a comparison.
 
 
1 hour later…
7:47 AM
@JerryCoffin Writing a subroutine in C.
 
8:08 AM
@John As far as I know, that machine never had a C compiler--and I'm pretty sure all of them with modern C compilers deal with +0 vs. -0 automatically.
 
I see. Thank you so much.
 
Surely. And by the way: if you find out about a modern machine where this is really an issue, I'd love to hear about it. I don't think it exists, but it's always possible that I'm wrong, and I'd like to know if I am.
 
8:24 AM
I can't fully remember what the teacher taught(roughly remember -0.0 and +0.0 and I should pay a attention to compare two doubles). I would go out of my way to make it clear. Thank you.
 
9:01 AM
sure, comparing floating point numbers can be an issue (that's why people do comparisons with an epsilon, check for NaNs, etc.). But I don't think I've ever seen in practise someone doing like a memcmp on a float or something like that and get "-0.0 != +0.0" out of that
 
9:51 AM
@PeterT With memcmp they would compare as not-equal. But there's quite a bit that can go wrong trying to use memcmp to compare floating point numbers.
 
 
1 hour later…
10:58 AM
yeah, I worded that poorly, I meant that I've never seen anyone bitwise compare floats and expect to get useful arithmetric comparisons out of it
 
 
4 hours later…
2:56 PM
How the hell do I feature test for "__builtin_FILE" , a simple "#ifndef __builtin_FILE" doesn't seem to work
 
nwp
> This function is the equivalent of the preprocessor __FILE__ macro
Just use __FILE__ and don't feature test?
 
can't use FILE in "int func(std::string msg,std::string file = FILE)"
I figured it out, it's __has__buildin
(which I need to feature test too, but that works with ifndef)
 

« first day (1655 days earlier)      last day (1200 days later) »