C
cr88192
Flash Gordon said:cr88192 wrote, On 23/08/07 16:09:
You are trying to reduce a number by a factor not trying to move bits.
They are conceptually different things. Try using a shit to halve a
floating point number as see how far it gets you.
but, a float and an integer are different concepts though...
not sure of why one would consider using a shift on a float...
Shift is for moving bits, divide is for scaling. Otherwise shift would
work on floating point and would have behaviour defined by the C standard
for negative numbers (it leaves it for the implementation to define the
result of right shifting a negative number).
ok, makes sense.
No, it is a question of using the wrong word. One that in some situations
happens to be similar, but in many situations means something completely
different.
the situations are different though.
as noted above, an integer and a float are conceptually different.
if I am speaking to someone do I count in floats? no, I count in integers...
Yes, it is a trick.
The shift operator is a basic operator for moving bits, using it to divide
is a trick and one that does not work in all situations.
it works on integers, integers are the context and the situation.
sizes are generally not negative either.
there is no problem as I see it.
Code riddled with casts probably is bad.
Code using a lot of shifts for shifting bits, NOT for division, could be
good.
ok, but then one has to differentiate: when is the concept shifting bits and
when is it division?...
this is a subjective matter.
No. However a shift works in terms of bits, not in terms of arithmetic.
but on integers, bit ops are arithmetic...
makes nearly as much sense in conversation as it would in C.
we ask someone 'what is 12 and 7?' they say '8'...
Several of the things above are reasons for using divide rather than
shift.
if one is confused as to whether not they are dealing with an integer...
what if I meant to grab an apple but instead grabbed a potatoe and proceeded
to eat it as said apple. people would look oddly, and then maybe ones'
stomach gets irritated from the raw potatoe...
so, casually eating an object raw is valid for an apple but not for said
potatoe.
likewise, we put potatoes in soup but not apples.
same difference really...
or a bigger mystery (OT, but as an example):
when someone can claim adherence to a certain religion and do things which
are condemned within the doctrine of said religion, meanwhile knowing the
doctrine, and then believe that their actions are moral (presumably within
the bounds of said religion).
this has happened recently, and after several months I still haven't figured
it out.
do they deny their actions? no.
do they deny the doctrine or the existence (or interpretation) of the
indicated statements? no.
do they admit that their actions are immoral? no.
this makes little sense really...
like some kind of bizarre paradox as to their reasoning...
(throwing philosophy at the problem still does not resolve it...).
The issue of you making a mistake that you would not have done had you
stuck to doing simple integer division is a good reason for using integer
division.
potentially, but this makes an assumption about ones' thought process.
if one always types shifts, one thinks shifts, one does not think division
unless one were first thinking of division, which I assert that I was not
(which is why I think I missed such an obvious answer).
What do you get if you right shift -1? On some machines it will be 32767
on others it will be -1. Does that sound like division to you?
different context.
one machine is probably an x86 in real mode with an int being 16 bits and
using shr.
the other is probably using sar.
Not relevant since a shift is not a different representation for division,
it is a different operation.
it is an operation relevant to a situation, that situation being positive
integers...
I was not claiming it was also sane for floats or for negatives.
Code is written for other people, not just the original author or the
compiler.
maybe.
if other people ever actually read said code.
Linear is another natural growth curve.
except that linear is not a curve...
Ah, so you realise now that suggesting a 4/3 curve makes less sense than
suggesting using a curve that will give good performance. My example above
was extreme, but there are plenty of less extreme examples.
the question is then what curve gives the best performance, which may depend
on the situation.
it is a tradeoff really between number of reallocations and wasted space.
4/3 is more conservative with space than 3/2, which is still more
conservative than the golden ratio.
so the question is then of rate of growth and likelyhood of continued
growth.
and, for the previous topic:
it is by some odd convention that when we see a division by undivisible
integers that we realize that it has a non-integer output.
I guess it is also by similar convention that we realize that negative even
roots are imaginary and that non-integral exponents of negative bases are
complex...