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