Well, the question sort of implies that you're needing to implementing Math.max yourself, for whatever reason. Probably as an exercise. It doesn't make sense to reuse a library that implements the feature if you're explicitly being asked how you would implement it yourself.
Where's the Julia programmer that hits every one of these with @benchmark and then works for six hours to shave three nanoseconds off of the fastest one?
Simple, really. Abs(x-y) is the difference between the two numbers, absolute, so positive value. So, adding abs(x-y) to the smaller of the two numbers turns it into the bigger number. Plus the bigger number, now you have 2 times the bigger number
Exactly, I don't understand why languages have decided that every keyword needs to be as randomly minified as possible.
fn, def, rune(ok that's not minified, just a dumb name), fmt, std. Many of these things aren't new, but programmers recognize descriptive variable names are important, the same should be true for keywords.
Wow that's a very exhausting language. I dropped your code into an online rust to asm converter and it actually wasn't more! I did try to post it for fun but lemmy kept messing up the code block. Oh well, wasn't that amusing anyway!
GNU C. Also works with Clang. Avoids evaluating the arguments multiple times. The optimizer will convert the branch into a conditional move, if it doesn't I'd replace the ternary with the "bit hacker 2" version.
Guess only work with integers, specially for the floor function that is going to give you an integer at the end everytime.
Not my idea, learned it somewhere while doing college in an statistics class. The idea is that the exponential function grow really fast, so small difference on variables become extreme difference on the exponential, then the log function reverse the exponential, but because it grew more for the biggest variable it reverts to the max variable making the other variables the decimal part (this is why you need the floor function). I think is cool because works for any number of variables, unlike mathematician 2 who only work for 2 variables (maybe it can be generalized for more variables but I don't think can be done).
For a min fuction it can be use ceiling(-ln(e^-x + e^-y))
Engineer I guess... Thief is the objectively better enterprise programmer option but I don't know why I always forget about it and just write a ternary ¯\_(ツ)_/¯
And then your customer changes their mind. Instead of two numbers, they will now input three numbers. How easy will it be for you to change your code?
And then the customer changes their mind. Instead of three numbers, they will now input any series of numbers. How easy will it be for you to change your code? And why didn't you already do this is the previous step?
And then the customer changes their mind. Instead of any set of numbers, they will now input numbers and text. How easy will it be to change your code?
And then the customer changes their mind. They now have no idea of what they're sending you or if they're even sending you anything.
Nevermind the code now, you already did that in the previous step, right?
How easy will it be to explain what you're invoicing them for?
If only you'd done the most bloated and well documented function first, you could have saved yourself the time and your client for the money.
I mean this is the kind of shit my boss would argue about. Why pay for the first attempts that didn't work.. blabla bla. He always ends up paying but it's always such a hassle.
Listen, in industry programming (and for personal projects if you want to get them done), the thief is the way to go. By all means, challenge yourself to understand each of these functions, but 99% of day to day development will not look like this.
How much time have you spent doing it? What part didn't you understand? If it's the bit shifting stuff, don't worry about it - hardly anyone actually knows how that works unless they look it up.
About a year with varying levels of commitment and intensity.
I kind of just threw myself into the deep end. Which was a rewarding but frustrating experience. My first project was one hot encoding 400gb of reddit porn to try and teach stylegan3 how to make porn. And then turning the function on in stylegan3. And then there was validating the images and ditching the ones that erroted. Resizing the whole datasets. Using ffmpeg to extract stills from the gifs and mp3s
I found stable diffusion existed like 5 days into actually training it which was bitter sweet. I mean. No way it would have produced actual porn but I was really looking forward to the horror.
I taught myself as I went along which is a great way to learn but it's super disheartening when I see the math that's second nature to anyone whose studied this stuff academically.. I don't like math. In fact I hate it, and no matter how skilled (or not) a coder I become I'll never learn calculus sometimes makes it all feel like a fools errand.
Otherwise, realistically, I’m prob the worst of all worlds … the procrastinator waiting/hoping to be the pair programmer that has hopefully remembered to just be the thief.
here’s another mathematical approach (that has the added benefit of only working when x and y are both positive).
let f denote the linear functional on ℝ2 defined by f(1,0) = x and f(0,1) = y (and extend by linearity). then the operator norm || f || is equal to max(x,y).