Math::Quaternion — Math-Quaternion

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

WikipediaRakuBoostdwhRAW
a$.rR_component_1realReal____________ part of a Q (as accessor)
b$.iR_component_2imag_iFirst_ imaginary part of a Q (as accessor)
c$.jR_component_3imag_jSecond imaginary part of a Q (as accessor)
d$.kR_component_4imag_kThird_ 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
.
normabsabssum_of_squares( r,i,j,k ).sqrt
normnormsum_of_squares( r,i,j,k )
abs(unreal)abs_imagsum_of_squares(i,j,k ).sqrt
norm(unreal)norm_imagsum_of_squares(i,j,k )
argatan2( sum_of_squares(i,j,k ).sqrt, r );
distance.
.
unrealimagself.( 0.0,i,j,
conjself.(r, -i, -j, -k );
operator *self.(r, -i, -j, -k );
signumabsq = sum_of_squares( r,i,j,k ).sqrt; return ( absq == 0.0 ) ?? self !! self.new( r/absq, i/absq, j/absq, k/absq );
sqrself.( r*r - i*i - j*j - k*k, 2*r*i, 2*r*j, 2*r*k );
inverseself.new: (r,-i,-j,-k) / sum_of_squares( r,i,j,k )
versorself / sum_of_squares( r,i,j,k ).sqrt
.
is_nanr != r or i != i or j != j or k != k;
is_infany(r,i,j,k) == any(PosInf,NegInf)
is_neg_infall(_,i,j,k) == 0 and r == NEG_INF;
is_pos_infall(_,i,j,k) == 0 and r == POS_INF;
is_real_infall(_,i,j,k) == 0 and r == any(POS_INF,NEG_INF);
is_realis_realall(_,i,j,k) == 0
is_zerois_zeroall(r,i,j,k) == 0
is_complexall(_,_,j,k) == 0
is_imaginaryis_imaginaryr == 0
.
rotateWhen |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.

SEE ALSO

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.

# vim: expandtab shiftwidth=4

Math::Quaternion v0.2.1

Hyper-complex numbers as objects with operators

Authors

    License

    Artistic-2.0

    Dependencies

    Test Dependencies

    Provides

    • Math::Quaternion

    The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

    Built with Podlite — the markup and publishing tools behind this site.