Comments (5)
@Nairou That's an interesting case I hadn't thought of. And to @RandyGaul's point, if you want to use the mul
style of math, the function names are probably so verbose that you would have to #define mul HMM_Multiply
anyway, just to make them tolerable.
My biggest issue with the overloaded versions is that they don't really give you anything beyond the operator overloads (besides a more visible order of operations, I guess). If someone wants to take the @RandyGaul approach, I would rather just let them create mul
in their own project with all the overloads they want. That way they can extend it to other things outside of Handmade Math.
from handmademath.
I could imagine some C++ like this feature of just being able to call HMM_Multiply with whatever data types and not have to call the explicit functions for that data type. Either way Iām not torn on keeping them or not
from handmademath.
Personally I prefer mul kind of function in C++.
The reason is if we concatenate a few matrices like so:
D = A * B * C
D = C * B * A
It isn't extremely clear what the order of intended operations is just by looking at the *
operator. This is a problem when someone opens up the math header and wants to create a transform hierarchy, but isn't sure what semantic ordering to apply until they see someone else using the header as an example. But, if there is a mul function people can use either ordering however they like, explicitly, and don't need to see sample code to figure out how to use the header.
D = mul(mul(A, B), C);
D = mul(mul(B, C), A);
I overload this mul function for matrix to matrix, matrix to vector, quaternion to vector, axis-angle to vector, and so-on, transform to transform, transform to vector, and so on.
One more advantage is a transposed multiply can be implemented, and can be potentially easier to on the compiler's optimizer. Compare the two options below for multiplying a tranposed matrix with another matrix.
C = transpose(A) * B;
C = mul_transposed(A, B);
The mul_transposed
function can directly implement the operations in-line for transposed multiplication, without making a transposed copy of A
.
The final reason, is adding more mul functions is really easy. I have similar mul functions (in my own code) for transforming shapes like planes and rays, or even arrays of vectors.
from handmademath.
I no longer use the overloaded functions either. I have also been tripped up in the past by reading two versions of each operation in the documentation (usually via search), trying one, and learning it was just an overload of something else.
from handmademath.
HMM 2.0 preserves the C++ overloads.
from handmademath.
Related Issues (20)
- New prefix features need robust testing HOT 1
- Functions in the HANDMADE_MATH_IMPLEMENTATION section are missing the HMM_PREFIX(...) macro HOT 2
- mat3 HOT 2
- Clarify ambiguous term "Column-major" HOT 2
- User-overridable linkage HOT 2
- 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
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.