Quaternion type: Difference between revisions
Content deleted Content added
→{{header|PureBasic}}: Added PureBasic |
m →{{header|Ada}}: whitespace |
||
Line 28:
=={{header|Ada}}==
The package specification (works with any floating-point type):
<lang Ada>generic
type Real is digits <>;
package Quaternions is
Line 44 ⟶ 43:
function "*" (Left, Right : Quaternion) return Quaternion;
function Image (Left : Quaternion) return String;
end Quaternions;</lang>
The package implementation:
<lang Ada>with Ada.Numerics.Generic_Elementary_Functions;▼
▲with Ada.Numerics.Generic_Elementary_Functions;
package body Quaternions is
package Elementary_Functions is
Line 106 ⟶ 103:
Real'Image (Left.D) & "k";
end Image;
end Quaternions;</lang>
Test program:
<lang Ada>with Ada.Text_IO; use Ada.Text_IO;
with Quaternions;
procedure Test_Quaternion is
Line 135 ⟶ 130:
Put_Line ("q1 * q2 = " & Image (q1 * q2));
Put_Line ("q2 * q1 = " & Image (q2 * q1));
end Test_Quaternion;</lang>
Sample output:
<pre>
|