Peeter Joot's (OLD) Blog.

Math, physics, perl, and programming obscurity.

Archive for July, 2011

strange looking predicate!

Posted by peeterjoot on July 6, 2011

The following code fragment was suggested today by a compiler guru as a way of checking for a floating point overflow or underflow:

double tmp = foo() ;

if ( tmp - tmp != tmp - tmp) 
{
   // handle floating point overflow or underflow.
}

Apparently, this works (at least for one compiler) because if tmp is +inf or -inf, subtracting it to itself will return NaN, which compares different to itself!

It will be interesting to see if this works on more than one compiler and in both optimized and debug build modes.

Posted in C/C++ development and debugging. | Tagged: , , , | Leave a Comment »

Portions of a (yet unsent) letter to my brother who has foolishly joined the marines. Perhaps too strong?

Posted by peeterjoot on July 4, 2011

[snip]

I know that we’ll never likely agree about the validity of military service. I’m not about to pretend that I don’t find US foreign policy terroristic (and there’s a massive irony to that), but you are still my brother, and I care for you. As I see it you are now stuck in your service role, having contracted to do so. I also realize that this was your choice, so you must believe you are being given the opportunity to do good. I view that as a remarkably successfully marketing job by the recruiters, and not one that matches reality. Hopefully you will actually have an opportunity to do some good, but I don’t have optimistic hopes that militaristic action ever creates such opportunities.

As I’ve said before, I worry about the physical dangers of your choice, and the emotional ones. You’ll have to survive both being the target of massive hatred, against all those that the US has imposed their will and imperialistic tendencies against. You’ll also likely have to deal with the inevitable mental and emotional strain of killing other human beings, in particular innocent civilians or those that feel wronged by the invasions imposed upon them. You’ve told me that regulations prohibit you from discussing your opinions on US policies, or even sharing your rational for joining the Marines. That is, until your service is complete. I truly don’t know what led you to make the decisions you did. But that isn’t going to change now, so you’ll have to make the best of it. I hope for your sake that you are left in a position that does not put you in a position to be killed or to have to kill others.

Last time we talked you said you were due to be posted to a new service location. Has that now happened? I hope that you ended up with the embassy guarding job that had been described to you. Did it end up being in Spain, as theorized? I hope so, since that should be a relatively peaceful and uneventful location to serve. Once that guarding tour is over, are you back to the USA before the next deployment?

[snip]

This letter was written in a stream of consciousness fashion, and I’ve sprouted just about anything that came to my head without inhibition. Hopefully, this won’t cause any damage. I don’t want to end up estranged from you, in a damaged relationship, like you and Dad. I’m hoping that you can both start communicating again too, as hard as this may be for both of you. If you are both completely honest with each other, you’ll have an opportunity to deal with whatever resentments may be sitting there keeping you both apart. Fixing this can only be done with communication. Repairing your relationship will probably require that you somehow explain your choices to Dad. He doesn’t understand why you’ve chosen the military any better than I do. If you open your soul and explain all your motivations, even if they are simple ones (like wanting to have some independence and make your own decisions), then you can fix the relationship. Otherwise it will fall to pieces and continue in that direction. You’ll have to make yourself understood, because I doubt very much that Dad understands why you have made your choices (I’ve known you twice as long and can’t understand why you’d choose to be a Marine). I’d like to understand you too, but for that to happen, you’ll also have to understand me, which is why I’ve been brutally honest here. It is honesty that is based on love and confusion.

With all my heart, I love you [redacted]. I hope that you’ll not be offended by my honesty, and that you’ll write back. I also hope that you overcome all odds and prosper in your role as a Marine, and do get a chance to do some good.


ps. I’m still amused by your revelation that there are regulations against getting sunburnt out of service (destruction of government property), and also regulations against non-missionary style sex in the Marines. What happens to somebody that gets caught getting a sunburn on their back because they are doing it doggy style for too long in the hot sun?

Posted in Incoherent ramblings | Leave a Comment »