Comments (6)
I don't know what you mean. They allow you to access elements of vectors by index without writing .Elements
, if you're using C++. So like myVec3[2]
instead of myVec3.Elements[2]
.
from handmademath.
Ahh, sorry, I though the issue title was self-explanatory, but there's always room for misunderstanding. :)
I meant the operator's signature, of course, and (as I noted), specifically its arg. passing approach.
IOW, why the ref? Just pass Index
by-val.
from handmademath.
I meant the operator's signature, of course
When working with humans, I recommend communicating using words and sentences so humans can understand.
Pass-by-reference vs. pass-by-val literally doesn't matter: https://godbolt.org/z/jT63zqWWh. If you believe it does matter and can demonstrate this in godbolt, perhaps we can consider making a change.
from handmademath.
Wow, sorry that my friendly suggestion, and my apology both apparently rubbed you the wrong way.
In the hope of some understanding, still: given the context of a) maths, b) C++ coding, and c) the pretty common & well-known old C++ habit of passing everything* by const&, I thought that my notation-heavy (and admittedly too condensed) message would click. I totally understand that it didn't, absolutely fine, maybe even I wouldn't understand it myself. I should've been less cryptic. Sorry again. And misunderstandings are indeed abundant, everywhere, all the time, with everybody -- most of the time we just don't even notice. That's what I meant by my sarcastic remark, and nothing personal.
* except, in your code, AFAICR, it seems to be not done for much else (I may remember wrong) -- that strange (mostly just cosmetic) inconsistency was what made me assume (wrongly then, I suppose) that it could probably be just a copy-paste remnant from older versions
As to Godbolt and stuff: I didn't mean to suggest it for performance, I meant it for a slight code readability improvement (noise reduction), precisely because the more convoluted formulation has no benefits.
from handmademath.
Passing everything by pointers or references is not a good habit for certain code as it can introduce pointer aliasing and cause a performance hit.
from handmademath.
Sure, so if we want to assess values vs. references then we should do so holistically and not for some specific operators based on "readability".
Currently we have:
float &operator[](const int &Index)
(get vector element)HMM_VecN &operator[](const int &Index)
(get matrix column)HMM_T operator+(HMM_T Left, HMM_T Right)
(add, subtract, multiply, and divide vectors, matrices, and quaternions)HMM_VecN &operator+=(HMM_VecN &Left, HMM_VecN Right)
(same operators combined with assignment)HMM_VecN operator*(HMM_VecN Left, float Right)
(vector or matrix * float, and the reverse)HMM_VecN operator*(HMM_MatN Matrix, HMM_VecN Vector)
(matrix * vector)HMM_Bool operator==(HMM_VecN Left, HMM_VecN Right)
(vector equality and inequality)HMM_VecN operator-(HMM_VecN In)
(vector negation)
Clearly most of them are indeed passing by value. I suppose we have to trade off the costs of copies vs. the cost of pointer aliasing, but surely these will almost always be inlined anyway. If passing by reference makes it less likely to inline due to pointer aliasing, then yeah, we should probably switch.
from handmademath.
Related Issues (20)
- Ship a set of basic math functions as an easy CRT alternative HOT 2
- Support unary minus operator on vectors HOT 2
- Fully inline Handmade Math HOT 2
- CI is not working HOT 2
- Divide by zero when calling HMM_Slerp with two identity quaternions HOT 3
- Unnecessary Square Root HOT 4
- Rotate point by quaterion HOT 1
- Where's the function to inverse a matrix? HOT 2
- Request - document fundamental choices made in handmade math HOT 2
- Remove HMM_PREFIX HOT 1
- Make naming more consistent and concise HOT 1
- HMM 2.0 Design HOT 1
- Use _Generic in C? HOT 3
- Unroll our loops HOT 2
- Consistent results in calculations HOT 8
- Convert HandmadeMath to double HOT 1
- Vector to matrix multiply arguments have the wrong order HOT 1
- `HMM_LinearCombineV4M4` has incorrect name and naming of arguments HOT 2
- Provide ASin, ATan, ATan2 functions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from handmademath.