CS people what do you call // ?
-
@ehproque @futurebird I'm an astronomer. Let's call it ten for now...
@khleedril @futurebird I'm a quantum physicist, let's call it 1
-
@futurebird I have no idea what this even means, but I call it "Slash, slash."
You and the whole fifth grade.
-
@khleedril @futurebird I'm a quantum physicist, let's call it 1
@khleedril @futurebird ℏ=h, where is your God now
-
CS people what do you call // ?
As in 16//5=3
* integer divide
* double divide
* floor
* floor divide@futurebird Comment?
*ducks*
-
@futurebird a comment
@futurebird in all seriousnessness, the use of "floor divide" implies the result is rounded towards negative infinity, in contrast with "trunc divide" , which implies rounding toward zero, an important distinction when one operand turns out to be negative. Now here's a question: in your favorite languages, which way does integer divide behave? Does the language definition even require a particular behavior? (C90 and C99 for example call it "implementation defined". )
-
@futurebird I used to call it integer division until I learned that at least in Python it doesn't actually return an int.
Now I just call it The Thing That Looks Like It Does What I Need But Better Stay Away From.@martok this operator has returned an int since it was added in Python 2.2, so this seems weird?
-
@futurebird Comment?
*ducks*
@futurebird Jokes aside, is it a floor or a towards-zero like the awful C "division" operator? That would affect proper naming a lot.
-
CS people what do you call // ?
As in 16//5=3
* integer divide
* double divide
* floor
* floor divideI can't read this and not interpret // as a start-of-line-comment marker. So this line is just 16. And I call 16 an integer.
-
@martok this operator has returned an int since it was added in Python 2.2, so this seems weird?
@jhominal Only if both arguments are int. If either is float, the result is float even if its value is by definition int-ish.
I still think this violates the Principle of Least Astonishment, that's why I just don't use it anymore. int(a/b) is not that much more typing.
-
@futurebird nobody knows! There's like a zillion ways to do it because there isn't something like a
"
include <maths>
maths::pi
" -
CS people what do you call // ?
As in 16//5=3
* integer divide
* double divide
* floor
* floor divide@futurebird Years ago I got offered "show your Python skills" quiz on LinkedIn and the answer to this question was given as "integer division". I was so furious I put in a complaint. It is, of course, "floor division". And Python-style modulus is the One True '%' operator –C's remainder can get in the bin.
-
-
-
-
@futurebird @yonder @ehproque Newton's method converges wonderfully quickly, so it's often a good place to start. I believe that CORDIC algorithms can also do square roots (although I haven't seen or derived one myself) -- those can be nicer for implementation if you don't have an FPU (or are building one), because they tend to be all about adds and bit-shifts and not much else.
CORDIC only generates one digit per iteration, though, whereas Newton doubles the precision each time.
-
um... not really. What do you do? load a math library?
I mean, how much pi do we need? Just type out ten decimal places and make it a global.
@ehproque @futurebird i need more pi
-
Can random.random() be stuck in a constexpr to do that at compile time or did someone rightfully shoot down the idea of compile time nonsererminism?
-
@ehproque @futurebird i need more pi
@burnitdown @futurebird I'm out, but here's some cake

-
Can random.random() be stuck in a constexpr to do that at compile time or did someone rightfully shoot down the idea of compile time nonsererminism?
We don't need any random numbers to be THIS terrible.
inside=0.0
resolution=100
for x in range(resolution):
x=x/resolution
for y in range(resolution):
y=y/resolution
if x*x+y*y<1:
inside+=1pi=4*inside/(resolution*resolution)
print(pi)
-
@futurebird in all seriousnessness, the use of "floor divide" implies the result is rounded towards negative infinity, in contrast with "trunc divide" , which implies rounding toward zero, an important distinction when one operand turns out to be negative. Now here's a question: in your favorite languages, which way does integer divide behave? Does the language definition even require a particular behavior? (C90 and C99 for example call it "implementation defined". )
@llewelly @futurebird floor can also be defined as going toward zero.
Programmers are amazing at not knowing the foundations of things. I worked somewhere that was absolutely confounded by numpy’s use of statistical rounding (x.50 goes to the even value not up, to avoid biasing your data in a systematic manner). I, freshly graduated from college and having taken a stats course, knew what it was immediately.