txt: ## dist_zef-raku-community-modules-Math-Quaternion.md
  [![Actions Status](https://github.com/raku-community-modules/Math-Quaternion/actions/workflows/linux.yml/badge.svg)](https://github.com/raku-community-modules/Math-Quaternion/actions) [![Actions Status](https://github.com/raku-community-modules/Math-Quaternion/actions/workflows/macos.yml/badge.svg)](https://github.com/raku-community-modules/Math-Quaternion/actions) [![Actions Status](https://github.com/raku-community-modules/Math-Quaternion/actions/workflows/windows.yml/badge.svg)](https://github.com/raku-community-modules/Math-Quaternion/actions)
  
  # NAME
  
  Math::Quaternion - Hyper-complex numbers as objects with operators
  
  # SYNOPSIS
  
  ```
  use Math::Quaternion;
  
  ```
  
  # DESCRIPTION
  
  This distribution implements an OO class for Quaternions, which are the simplest of the hyper-complex numbers. It adds the operators needed for basic math on the Qs, and should be a good base class for future modules to support the other hyper-complex numbers.
  
  # RECOMMENDATIONS
  
  I intend this module to be a high-quality example of Raku numeric OO, usable as a reference for future module authors.
  
  # WARNINGS
  
  This module is a mostly-from-scratch re-implementation of Quaternions; its API differs from the excellent Perl Math::Quaternion module.
  
  # GLOSSARY
  
  | Wikipedia | Raku | Boost | dwh | RAW |
  | --- | --- | --- | --- | --- |
  | a | $.r | R\_component\_1 | real | Real\_\_\_\_\_\_\_\_\_\_\_\_ part of a Q (as accessor) |
  | b | $.i | R\_component\_2 | imag\_i | First\_ imaginary part of a Q (as accessor) |
  | c | $.j | R\_component\_3 | imag\_j | Second imaginary part of a Q (as accessor) |
  | d | $.k | R\_component\_4 | imag\_k | Third\_ imaginary part of a Q (as accessor) |
  |  | .coeffs |  |  | (r, i, j, k) # List, not arrayref nor vector |
  |  | .v |  |  | (i, j, k) # List, not arrayref nor vector |
  |  |  |  |  | . |
  | norm |  | abs | abs | sum\_of\_squares( r,i,j,k ).sqrt |
  |  |  | norm | norm | sum\_of\_squares( r,i,j,k ) |
  |  |  | abs(unreal) | abs\_imag | sum\_of\_squares( i,j,k ).sqrt |
  |  |  | norm(unreal) | norm\_imag | sum\_of\_squares( i,j,k ) |
  |  |  |  | arg | atan2( sum\_of\_squares( i,j,k ).sqrt, r ); |
  | distance |  |  |  | . |
  |  |  |  |  | . |
  |  |  | unreal | imag | self.( 0.0, i, j, k ); |
  |  |  |  | conj | self.( r, -i, -j, -k ); |
  |  |  |  | operator \* | self.( r, -i, -j, -k ); |
  |  |  |  | signum | absq = sum\_of\_squares( r,i,j,k ).sqrt; return ( absq == 0.0 ) ?? self !! self.new( r/absq, i/absq, j/absq, k/absq ); |
  |  |  |  | sqr | self.( r\*r - i\*i - j\*j - k\*k, 2\*r\*i, 2\*r\*j, 2\*r\*k ); |
  |  |  |  | inverse | self.new: (r,-i,-j,-k) / sum\_of\_squares( r,i,j,k ) |
  | versor |  |  |  | self / sum\_of\_squares( r,i,j,k ).sqrt |
  |  |  |  |  | . |
  |  |  |  | is\_nan | r != r or i != i or j != j or k != k; |
  |  |  |  | is\_inf | any(r,i,j,k) == any(PosInf,NegInf) |
  |  |  |  | is\_neg\_inf | all(\_,i,j,k) == 0 and r == NEG\_INF; |
  |  |  |  | is\_pos\_inf | all(\_,i,j,k) == 0 and r == POS\_INF; |
  |  |  |  | is\_real\_inf | all(\_,i,j,k) == 0 and r == any(POS\_INF,NEG\_INF); |
  |  | is\_real |  | is\_real | all(\_,i,j,k) == 0 |
  |  | is\_zero |  | is\_zero | all(r,i,j,k) == 0 |
  |  | is\_complex |  |  | all(\_,\_,j,k) == 0 |
  |  | is\_imaginary |  | is\_imaginary | r == 0 |
  |  |  |  |  | . |
  |  |  |  | rotate | When |q| == 1 |
  |  |  |  | sqrt | . |
  
  # ACKNOWLEDGEMENTS
  
  Thanks to:
  
  * Jonathan Chin for the original Perl Math::Quaternion module.
  * Solomon "colomon" Foster for encouraging this module's release.
  * Will "Coke" Coleda for fixes to match changes in Rakudo.
  * RosettaCode for the [challenge that provoked the initial code](https://rosettacode.org/wiki/Quaternion_type#Raku).
  
  # SEE ALSO
  
  * <http://en.wikipedia.org/wiki/Quaternion>
  * <http://en.wikipedia.org/wiki/Hypercomplex_number>
  
  # AUTHOR
  
  Bruce Gray
  
  # COPYRIGHT AND LICENSE
  
  Copyright 2010 - 2017 Bruce Gray
  
  Copyright 2024 Raku Community
  
  This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
  