Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/profelis/overload-operator
haxe macros experiment
https://github.com/profelis/overload-operator
Last synced: 30 days ago
JSON representation
haxe macros experiment
- Host: GitHub
- URL: https://github.com/profelis/overload-operator
- Owner: profelis
- Created: 2012-02-23T16:12:00.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-06-08T08:35:09.000Z (over 12 years ago)
- Last Synced: 2024-04-28T02:19:09.325Z (8 months ago)
- Language: HaXe
- Homepage:
- Size: 168 KB
- Stars: 27
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Looks Simn fork first - https://github.com/Simn/hxop
## haXe operator overloading tool (alpha)
Macros
@op(operator, [commutative=false])
@noOverload - ignore
Support operators
```
+ - * / % += -= *= /= %=
< > == != <= >=
& && | || ^ !
<< >> <<< ~
...
++x x++ --x x-- -x
```## Demo code:
* ComplexMath.hx
```
...@op("+", true) inline static public function add(a:Complex, b:Complex):Complex
{
return new Complex(a.re + b.re, a.im + b.im);
}@op("+", true) inline static public function addFloat(a:Complex, b:Float):Complex
{
return new Complex(a.re + b, a.im);
}@op("-x") inline static public function neg(a:Complex):Complex
{
a.re = -a.re;
a.im = -a.im;
return a;
}@op("/=", true) inline static public function idiv(a:Complex, b:Complex):Complex
{
var are = a.re;
var bre = b.re;
var div = 1 / (bre * bre + b.im * b.im);
a.re = (are * bre + a.im * b.im) * div;
a.im = (are * b.im + a.im * bre) * div;
return a;
}@op("==", true) public static function eq(a:Complex, b:Complex):Bool
{
return a.re == b.re && a.im == b.im;
}
...
```* Main.hx
```
...
class Main implements IOverloadOperator
{
// noOverload - ignore this method
@noOverload static public function main()
{
new Main();
}
public function new()
{
var c = new Complex(0, 1);
c *= new Complex(0, 1); // c = ComplexMath.imult(c, new Complex(0, 1));
trace(c);
}
}
```## Supported maths
* [ComplexMath](https://github.com/profelis/overload-operator/blob/master/src/deep/math/ComplexMath.hx)
* [QuaternionMath](https://github.com/profelis/overload-operator/blob/master/src/deep/math/QuaternionMath.hx)
* [Int32Math](https://github.com/profelis/overload-operator/blob/master/src/deep/math/Int32Math.hx)
* [Int64Math](https://github.com/profelis/overload-operator/blob/master/src/deep/math/Int64Math.hx)
* Beta [PointMath](https://github.com/profelis/overload-operator/blob/master/src/deep/math/PointMath.hx)