Replacement for @raoulb pr#914

See #914

ToDo:
- [x] tests
- [x] final rebase
```
In [93]: cos(7*pi/5)
Out[93]: -sqrt(5)/4 + 1/4
```