₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,330,696 members, 8,446,678 topics. Date: Thursday, 16 July 2026 at 11:27 PM

Toggle theme

Ektbear's Posts

Nairaland ForumEktbear's ProfileEktbear's Posts

1 2 3 4 5 6 7 8 ... 135 136 137 138 139 140 141 142 143 (of 485 pages)

ProgrammingRe: C++ Question by ektbear: 2:30am On May 28, 2012
Eh.

My point is, let the compiler do its job (optimize), and you do yours (code).

Trying to optimize basic operations like multiplication, division, etc...not clear it makes a lot of sense. Your compiler knows more about your CPU than you do.
PoliticsRe: Why Is South Africa More Developed And Stable Than Nigeria?? by ektbear: 2:07am On May 28, 2012
haha i wish i could see all these hidden posts
ProgrammingRe: C++ Question by ektbear: 1:44am On May 28, 2012
Highly unlikely to be GCC specific.

Implement your own divide by 10 function, that divides an integer by 10, using whatever bitshift operations you like.

I highly doubt it will outperform the compiler (whether GCC, Microsoft's compiler, etc)...
CelebritiesRe: D’banj’s Story: From A Security Guard To Topping Charts In The UK by ektbear: 1:42am On May 28, 2012
Up Skeebanj
ProgrammingRe: C++ Question by ektbear: 1:28am On May 28, 2012
Also, it doesn't make much sense to try to optimize division by say 10 using bit shifts.

Like, your compiler will probably do a better job of figuring out the fastest way of optimizing things for your processor than you will.

Like I said earlier, compilers these days are pretty smart..
ProgrammingRe: C++ Question by ektbear: 1:26am On May 28, 2012
Beaf: The bolded is almost correct. It is not a division in the sense that it only works for powers of 2. However, most divisions can be optimised by employing both bit shifts and multiplication, addition or subtraction; that is the reason for my last answer.
Well, since the default in C, C++ and Java for integer/integer division seems to be floor afterwards, then technically doing:

X / 2

and

X >> 1

are the same thing.

Of course in mathematics division of integers by 2 and right-shifting should not be the same. C++ is a weird language, lol
ProgrammingRe: C++ Question by ektbear: 1:23am On May 28, 2012
But it is trivial to generalize the first code sample I gave to work for:

a) Arbitrary-length integers
b) Returning the Kth digit rather than the first one (left-most).

If you understand the basic principle being used, you can easily generalize it.

The problem with your proposal is that:
a) It is probably slower
b) It is more error-prone, as LordZouga's example shows
c) It doesn't demonstrate that one actually understands certain things about math

So if it were me grading it, I certainly wouldn't give bonus points. It is a very ugly solution.
PoliticsRe: US Cuts Demand For Nigerian Crude by ektbear: 1:11am On May 28, 2012
CyberG: ^^ Both of you are missing something: the exports to Asia would be at reduced profit to compensate for the longer distance required to transport the oil. Plus, the Chinese are guaranteed to want anything and everything for rock-bottom cheap prices!
First point, agreed. More profitable for Nigeria to ship to the Eastern US rather than China.

Alas.
ProgrammingRe: C++ Question by ektbear: 1:09am On May 28, 2012
Bit shift twiddling is just division by (powers of ) 2. Or multiplication by 2.

However, that isn't relevant in this case, since I'm not dividing or multiplying by powers of two. I'm dealing with powers of 10.
ProgrammingRe: C++ Question by ektbear: 1:08am On May 28, 2012
Eh...that was an example so you guys get the pattern.

The problem as specified, I know exactly how many digits the number I'm given has. It is 5. So no if statements are required. I didn't use any if statements in my initial code, did I?
ProgrammingRe: C++ Question by ektbear: 12:59am On May 28, 2012
So if you have the integer:

7

And someone asks you for the left-most digit.

What will you do?

Will you convert to string, then read off the left-most element of the character array?

No. You'll just return the number 7.

What if you have the number 87?

Will you convert to string?

No. You divide by 10 (getting the result 8.7) and floor if necessary. (But in C++, evidently the flooring happens automatically, so just divide by 10.)

Etc, etc...

Converting to string makes zero sense.
ProgrammingRe: C++ Question by ektbear: 12:55am On May 28, 2012
Beaf. You are missing the larger point I am making.

If you have some function f(x) that converts an integer into its string representation, then necessarily it will have to do some sort of digit popping.

The only way I know of doing this is through dividing by (powers of) 10.

In fact, I suspect that it is impossible to convert arbitrary digit sequences into their string representations without some algorithm like this.

It doesn't make any sense to rail against division, and then call some function that has division inside of it.

So again...the key point is that converting sequences of digits to string will require division. Several times.
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 12:46am On May 28, 2012
The unfortunate reality I have to deal with is that 95%+ of the economic policies that right-wing parties like the Republicans propose/support I agree with.

Alas, for other reasons I cannot identify with this party, and am a Democrat. How I wish the Republicans would focus less on this ugly social stuff they do so I can join them.

All this "big government", "awoof for all" stuff that leftists promote...all it does is to slowly kill a country.
ProgrammingRe: C++ Question by ektbear: 12:38am On May 28, 2012
I don't even understand the way you guys reason.

You want to build a box which does this:

Integer->[f(x)] -> Left-most digit

Rather than doing it in the most direct way possible, you guys want to do:

Integer->Convert to string representation->grab left-most character of string->convert this left-most character back to digit.

Seems so unnecessary, roundabout, and wasteful.
ProgrammingRe: C++ Question by ektbear: 12:35am On May 28, 2012
Which real-time systems don't allow you to perform division? undecided

So you can do integer to string conversion on a real-time system, but not division by 10? grin

lol
ProgrammingRe: C++ Question by ektbear: 12:32am On May 28, 2012
1. There is nothing "destructive" about division. Nothing is getting destroyed here..
2. Division isn't particularly computationally expensive, to my knowledge. Same computational complexity as multiplication. And your processor will have specialized circuits to do it fairly efficienctly.
3. I don't know of any way to convert an X digit integer into a stream of characters without doing some sort of division. How on earth does one convert the number 12345 into the string "12345" without popping off digits? And the only way I know of to pop off digits is to do division.
If you are calling some function that converts an integer into a string representation, under the hood it is probably doing a sequence of digit operations like that of the original function I had.
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 12:24am On May 28, 2012
Katsumoto: 1. After the devastation of WW2, it needed to support and reward its citizens for the war effort. Despite winning the war for Britain, Churchill lost to Labour's Clement Attlee in 1945 and Attlee used his 6 years to institute various welfarist programs. Despite, the conservatives returning to power for the next 15 years, Harold Wilson, another labour PM, would institute more welfare programs. It is instructive to note that the UK went broke twice under successive Labour governments in 1976 and 1979.

2. A mindset of entitlement is not best for innovation. People innovate when there is a need to survive. If the government gives you a home to live, pays you a weekly wage, and provides healthcare how are u going to be motivated to innovate?
Socialist, welfarist ideologies are one of the greatest evils that mankind has ever known.

The end result of these welfarist policies was to make the UK weak and sickly, ripe for overtaking by more vibrant and industrious peoples (Germans and Japanese).
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 12:19am On May 28, 2012
Anyway, my opinion at this point:

Germans and Japanese=>cool cats
British => weaksauce

Step up your game, UK grin
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 12:17am On May 28, 2012
Can socialism/welfarism be blamed alone, though?

I was under the impression that Germany for example is pretty welfarist. France as well.

Or was Germany more capitalistic from the 40s to the 70s (or whenever it was they overtook the UK)?
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 12:12am On May 28, 2012
1. Why did the UK become welfarist?
2. Why did they stop innovating? Is there something in British culture that is not supportive of science and technology?
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 12:08am On May 28, 2012
Heck. UK was the largest aid recipient, if I'm reading the table in the middle of the page correctly:

http://en.wikipedia.org/wiki/Marshall_Plan
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 12:07am On May 28, 2012
Kats, it appears that the UK received money to rebuild after WW2 also.

So it isn't even the case that the US gave France, Germany and Japan money to rebuild, and the UK got nothing.

Somehow, they were just outcompeted and outmaneuvered after WW2.
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 12:04am On May 28, 2012
Right. But the question is, shouldn't:

a) Overseas empire
b) NOT getting your azz kicked in a war

be enough to remain wealthier and maintain your competitive advantage over Germany and Japan?

The Marshall program alone should not be enough to erase the two above advantages, no?

What mistakes did the UK make from the 1940s to 1960s that caused it to lose its previous edge over Germany, France, and Japan?
ProgrammingRe: C++ Question by ektbear: 11:54pm On May 27, 2012
There is always going to be a special case in which Compiler X produces "better" code (in whichever way you define 'better') than Compiler Y.

But the more important questions are:
a) for my particular case, which compiler is best?
b) which compiler typically performs better across most applications?

Perhaps for the applications you deal with, there is no difference. That is fine. However, for many other applications of interest to people (http://stackoverflow.com/questions/1733627/anyone-here-has-benchmarked-intel-c-compiler-and-gcc), there is a difference, and Intel wins hands down.

(b) is a more difficult question to answer and benchmark. However, my recommendation would be that anyone who has access to the latest Intel compiler for their system should use it over GCC.

Commercial generically does not mean superior, yes. But one might expect that the compiler designed by the same guy who designed the chip might perform better than a compiler written by some third party. So if you can afford it, go with the Intel compiler.
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 11:44pm On May 27, 2012
Interesting how much traffic threads like this get.


So my question is, why does the UK have the least amount of "swag" of all the developed nations? Shouldn't it be far ahead of Germany and Japan, both of whom were defeated in wars and never had the advantage of centuries of overseas empire?

UK even seems to be behind France.

Why is the UK such a laggard?
PoliticsRe: US Cuts Demand For Nigerian Crude by ektbear: 11:24pm On May 27, 2012
oyb: who knows we may even see a preponderance of gas powered cars

our bigger customers are going out the window. . .
Interesting article. I wouldn't be too worried about the long-term prices of oil and gas, though. China and India are not industrialized yet. And represent, what, 40% of humanity?

So demand should grow enough over the next 20, 30 years for prices not to fall too much.

It will be interesting to see how things turn out, though.
Foreign AffairsRe: Why Is England More Developed And Stable Than America? by ektbear: 11:20pm On May 27, 2012
[quote author=tpia@]hmph. undecided

sleeping with white women means the colour of skin is virtually insignificant?[/quote]grin
ProgrammingRe: C++ Question by ektbear: 11:16pm On May 27, 2012
My statement is correct.

The portability of the GNU compilers is nice.

But that doesn't mean that they produce code as efficient as Intel compilers.

I highly doubt that GNU-compiled code is as efficient as that of any commercial compiler. Hence, the statement is correct.
PoliticsRe: Nigeria (PDP) Vs South Africa (ANC) - The One Party State = African Democracy. by ektbear: 10:57pm On May 27, 2012
African democracy. Heh.

Though I suppose that Ghana and Liberia are good counter-examples?
PoliticsRe: US Cuts Demand For Nigerian Crude by ektbear: 10:54pm On May 27, 2012
oyb: who invited the afropseudoscientists /pseudo entrepreneurs /full time noisemakers to the discussions of professionals ?
An excellent question.

Anyway, interesting post texazzpete.
ProgrammingRe: Your Programming Experience And Your Languages. by ektbear: 10:34pm On May 27, 2012
Ruby as my main language since late 2009.

Python for like 2-3 weeks now (trying to make it my main language).

C++ and C in high school and a bit in college.

Octave all throughout college and present.

PHP for fun in high school.

Took a class in Java in college.

Oh, and of course, did some programming in BASIC at age 6 or 7 cheesy We used to have these book in the library that'd teach you how to get started programming in BASIC. They taught you the basic control structures.

So pretty comfortable with many different languages and syntax styles.

1 2 3 4 5 6 7 8 ... 135 136 137 138 139 140 141 142 143 (of 485 pages)