Speed of execution of the functions ceil(),round(),floor() - page 7

 
Andrey Kisselyov:

Let's take as an example:
if you change even the bitness of the machine, you switch to 64 bits and the accuracy of the machine has increased, your formula will stop working as the accuracy of the machine will be much higher than you set in your error.

With respect.

P.S. there may be other options where your formula will fail on a range of numbers. constantly adjusting error from switching to a different machine, or changes in compiler, which you are not informed, or when you change the representation of numbers in the machine, or from cutting a fractional part of the number when compiling a new version of the terminal ... You don't know what can change, and I don't think it's a good idea to do an IF or suffer to guess what's going to happen by writing an error over and over again...

I think this is something to think about.


I disagree. The formula(y=(int)(x+0.999999999999999997);) will not stop working when the accuracy is increased, it will work the same way. As before, the error will occur in the range of the fractional part of the number between DBL_EPSILON (the current value: 0.00000000000002222204460492503131) and 0.0000000000000003. Even if DBL_EPSILON decreases to zero (which of course it cannot), the range will increase by the size of the current DBL_EPSILON, i.e. by 2.2204460492503131e-016. I believe one can even ignore such an error range.

And what is the term "machine accuracy" anyway. There are standardised accuracies like double and other types. Your reasoning does not count. I'll say nothing about P.S.)) I am afraid to offend.

With respect.

 
Nikolai Semko:

I disagree. The formula(y=(int)(x+0.999999999999999997);) will not stop working when the accuracy is increased, it will work the same way. As before, the error will occur in the range of the fractional part of the number between DBL_EPSILON (the current value: 0.00000000000002222204460492503131) and 0.0000000000000003. Even if DBL_EPSILON decreases to zero (which of course it cannot), the range will increase by the size of the current DBL_EPSILON, i.e. by 2.2204460492503131e-016. I believe one can even ignore such an error range.

And what is the term "machine accuracy" anyway. There are standardised accuracies like double and other types. Your reasoning does not count. I will say nothing about P.S.)) I am afraid to offend.

Respectfully.

When applied to prices in the market, you can generally leave the accuracy at 5-6 digits, and since you are working in mathematics and do not know who and what will need your new fast calculation, you should apply the "principle of foolish behavior" according to which it does not matter who and when can put a value at which the function will err in calculations.

Respect yourself, anyone can rub your face in dirt, is it worth it to give an opponent a reason to do so by being rude? We're all evolved in something, while other things are just not interesting or not important for us.
Since we're talking about assembler and your idea of what happens to the code after the compiler, I'll tell you a few phrases that may make sense to you.

Because a processor has a limited number of bits in each register, adding and subtracting or any other operation in those registers has some tricky aspects when it comes to flags.
As someone who has worked in assembler you should understand what we're talking about.
so tell me at command ADD on different models of the processor whether there will be an overflow, if you write code on assembly language using the same number on different models and in general it can not fit in any register and will be truncated, from 8 bits of last generation to 64 bits and more current generation and how it can change in the future (technology development so fleeting, has passed just 40 years, and we already have a multi-core processors instead of a lamp early 80s)?

my respect.
 
It's better to open profiling and see where in your code execution is slow, and it's obviously not math functions. Most of them are loops, all sorts of queries and so on and so forth. math functions are among the fastest and trying to cut something out there is not very smart for me.

With respect.
 
Nikolai Semko:

All right, gentlemen, you've made your point. I'll change the ceil function for you:

This variant is 25-50% slower than variant:y=(int)(x+0.9999999999999997); but it is maximally correct, works for negative integers and is 3 times faster than ceil(x).

But myself, as a commoner and failed, I'll use the variant with nines, because I consider all your arguments boring and for me, someone who has been programming in assembler for a long time, and therefore knows what happens to the code after compilation, it's too much - to put checks where you can do without them.

Going over to personalities traditionally means a lack of arguments on the merits. But still I ask you a question. What made you cut the time of a million roundings from 8 to 5 or 2 milliseconds? What was the real load on the processor if even such delays turned out to be a bottleneck? I haven't encountered any such needs. Maybe it was something abstract, of academic interest?
 
Vladimir:
Going personal has traditionally meant a lack of substantive arguments.

I agree, as well as a lack of cultural behaviour, in an attempt to humiliate the other person.

Respectfully.

 
Andrey Kisselyov:
Concerning the "no credit", I did not give an assessment of your arguments and did not belittle your merits, as I wish you to. Respect yourself, rub your face in the dirt can anyone, whether to give your opponent a reason to do so, asking for rudeness in their actions? we all have developed in something, and that we are just not interested or irrelevant to us.
Vladimir:
Going for personalities traditionally means a lack of arguments on the merits.
Andrey Kisselyov:

I agree, as well as the lack of cultural behaviour in trying to humiliate the interlocutor.

Wow! I certainly apologise if I offended anyone. You must have been offended by what I said:

Nikolai Semko:

All right, gentlemen of the honors, that's settled. I'm changing the ceil function just for you:

But I myself, as a commoner and a C student, will use the variant with nines, because I consider all your arguments to be nerdish...

NikolaiSemko:

And what is the term "machine accuracy" anyway. There is standardised accuracy like double and other types. Your reasoning does not count. I don't speak about P.S. at all))) I'm afraid to offend.

Well, you know... I think you have a fertile imagination. In ordinary friendly banter you see "transfer to personality", "attempt to humiliate interlocutor", "belittling of merits" ...

Or did I miss something, and somewhere else I overstepped the boundaries of decency?

Sorry, Andrew, but I just apparently don't have enough knowledge and experience to understand what you wrote in that P.S.:

Andrey Kisselyov:
P.S. there may be other variants, when your formula will fail on a range of numbers. constantly adjusting error due to switching to another machine, or changes in compiler, which you are not informed about, or changes in machine representation of numbers, or cuttingfractional part of number when compiling in new versions of the terminal... I don't know what can change, I don't think it's a good idea to do IF or suffer to guess what's going to happen by prescribing an error over and over again...
I would be very grateful if someone could explain the meaning of what I've written.
Once again, I apologize for my tone. I always advocate mutual respect between colleagues and correct behaviour. The devil is on my mind.
 
Vladimir:
What prompted you to reduce the million rounding time from 8 to 5 or 2 milliseconds? What was the real burden on the processor if even such delays proved to be a bottleneck? I haven't encountered any such needs. Maybe it's something abstract, of academic interest?
Andrey Kisselyov:
It's better to open profiling and see where in your code lags, and it's obviously not math functions. Mostly it's loops, various queries and so on and so forth. Math functions are among the fastest and trying to cut something out there is not very smart, I think.
I don't know why you think I'm slow. On the contrary, I think my algorithms are the fastest. I'm just a bit of a speed freak. Of course, using such an alternative rounding function replacement gives very little gain, just fractions of a percent. But as the saying goes, from the world at large. This is also the case, for example, in aircraft and rocket science. In the struggle to reduce weight without compromising strength, everything is modified, even the bolts. Maybe that is one reason why, contrary to logic, nowadays aeroplanes are the safest mode of transport.
 
Nikolai Semko:

Wow! I certainly apologise if I offended anyone. You must have been offended by what I said:

Well, you know... I think you have a vivid imagination. In a simple friendly banter you see "personalization", "humiliation", "belittling"...

If you allow yourself to 'Ridicule' your friends, you have no friends, you have clowns around you whom you sometimes laugh at and do not value their friendship and opinion.

Nikolai Semko:

Or did I miss something, and somewhere else I overstepped the boundaries of decency?

I am not your friend, brother or even close person so that you can give you some kind of appraisal, all the more so PUBLICALLY.

Nikolai Semko:
Sorry, Andriy, I just apparently do not have enough knowledge and experience to understand what you wrote in that P.S.: I will be very grateful if somebody explains to me the meaning of what you wrote.

The meaning of what is written in P.S., which you can't understand for some reason is obvious, you don't know how the technique you use your fast formulas will develop, you don't know how the platform will develop, you don't know what will subsequently be added to the compiler and how numbers will be represented in processor registers space, you know nothing about it and to introduce a constant, saying that it will solve everything positively and always, is, so to speak, delusion.

If you take into account that your formula will be taken by other people from the forum and may put it into C or Pascal or something, you need to take into account these points too, maths has no limits either on platform or programming language.

Nikolai Semko:
Once again I apologize for my tone. I always advocate mutual respect between colleagues and correctness of behavior. I was out of line.

apologies accepted. do not make the same mistakes again, otherwise your words are meaningless rubbish.

Respectfully.

 
Nikolai Semko:
I don't know what makes you think I'm slow. On the contrary, I think my algorithms are the fastest. I'm just a bit of a speed freak. Of course, using such an alternative rounding function replacement gives very little gain, just fractions of a percent. But as the saying goes, from the world at large. This is also the case, for example, in aircraft and rocket science. In the struggle to reduce weight without compromising strength, everything is modified, even the bolts. Maybe that's one of the reasons why nowadays aeroplanes are the safest mode of transport contrary to logic.
I am in favour of a sensible approach to programming, where you can accelerate not against logic, it is better to do so, but any "disease" needs to be treated, as it is an aberration from a healthy way of life.

With respect.
 
Andrey Kisselyov:

If you allow yourself to "STUDY" your friends, you have no friends, you have clowns around you who you sometimes make fun of and don't value their friendship and opinion.

Looks like Nikolai was right about the nerds ))

Personally, I haven't seen any personal reference there. And you do have a lot of letters in your posts, but everything is off-topic and you seem to be arguing just for the sake of arguing.

Reason: