| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT RUN-TIME COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- A D A . N U M E R I C S . A U X _ G E N E R I C _ F L O A T -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- (Generic Wrapper) -- |
| 9 |
-- -- |
| 10 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 11 |
-- -- |
| 12 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 13 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 14 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 15 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 16 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 17 |
-- or FITNESS FOR A PARTICULAR PURPOSE. -- |
| 18 |
-- -- |
| 19 |
-- As a special exception under Section 7 of GPL version 3, you are granted -- |
| 20 |
-- additional permissions described in the GCC Runtime Library Exception, -- |
| 21 |
-- version 3.1, as published by the Free Software Foundation. -- |
| 22 |
-- -- |
| 23 |
-- You should have received a copy of the GNU General Public License and -- |
| 24 |
-- a copy of the GCC Runtime Library Exception along with this program; -- |
| 25 |
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- |
| 26 |
-- <http://www.gnu.org/licenses/>. -- |
| 27 |
-- -- |
| 28 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 29 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 30 |
-- -- |
| 31 |
------------------------------------------------------------------------------ |
| 32 |
|
| 33 |
-- This package provides the basic computational interface for the generic |
| 34 |
-- elementary functions. |
| 35 |
|
| 36 |
-- This version here delegates to interfaces that typically import as |
| 37 |
-- intrinsics the expected math functions. |
| 38 |
|
| 39 |
with Ada.Numerics.Aux_Long_Long_Float; |
| 40 |
with Ada.Numerics.Aux_Long_Float; |
| 41 |
with Ada.Numerics.Aux_Float; |
| 42 |
with Ada.Numerics.Aux_Short_Float; |
| 43 |
|
| 44 |
generic |
| 45 |
type T is digits <>; |
| 46 |
package Ada.Numerics.Aux_Generic_Float is |
| 47 |
pragma Pure; |
| 48 |
|
| 49 |
package LLF renames Aux_Long_Long_Float; |
| 50 |
package LF renames Aux_Long_Float; |
| 51 |
package F renames Aux_Float; |
| 52 |
package SF renames Aux_Short_Float; |
| 53 |
|
| 54 |
function Sin (X : T'Base) return T'Base |
| 55 |
is (if T'Base'Digits > LF.T'Digits |
| 56 |
then T'Base (LLF.Sin (LLF.T (X))) |
| 57 |
elsif T'Base'Digits > F.T'Digits |
| 58 |
then T'Base (LF.Sin (LF.T (X))) |
| 59 |
elsif T'Base'Digits > SF.T'Digits |
| 60 |
then T'Base (F.Sin (F.T (X))) |
| 61 |
else T'Base (SF.Sin (SF.T (X)))); |
| 62 |
|
| 63 |
function Cos (X : T'Base) return T'Base |
| 64 |
is (if T'Base'Digits > LF.T'Digits |
| 65 |
then T'Base (LLF.Cos (LLF.T (X))) |
| 66 |
elsif T'Base'Digits > F.T'Digits |
| 67 |
then T'Base (LF.Cos (LF.T (X))) |
| 68 |
elsif T'Base'Digits > SF.T'Digits |
| 69 |
then T'Base (F.Cos (F.T (X))) |
| 70 |
else T'Base (SF.Cos (SF.T (X)))); |
| 71 |
|
| 72 |
function Tan (X : T'Base) return T'Base |
| 73 |
is (if T'Base'Digits > LF.T'Digits |
| 74 |
then T'Base (LLF.Tan (LLF.T (X))) |
| 75 |
elsif T'Base'Digits > F.T'Digits |
| 76 |
then T'Base (LF.Tan (LF.T (X))) |
| 77 |
elsif T'Base'Digits > SF.T'Digits |
| 78 |
then T'Base (F.Tan (F.T (X))) |
| 79 |
else T'Base (SF.Tan (SF.T (X)))); |
| 80 |
|
| 81 |
function Exp (X : T'Base) return T'Base |
| 82 |
is (if T'Base'Digits > LF.T'Digits |
| 83 |
then T'Base (LLF.Exp (LLF.T (X))) |
| 84 |
elsif T'Base'Digits > F.T'Digits |
| 85 |
then T'Base (LF.Exp (LF.T (X))) |
| 86 |
elsif T'Base'Digits > SF.T'Digits |
| 87 |
then T'Base (F.Exp (F.T (X))) |
| 88 |
else T'Base (SF.Exp (SF.T (X)))); |
| 89 |
|
| 90 |
function Sqrt (X : T'Base) return T'Base |
| 91 |
is (if T'Base'Digits > LF.T'Digits |
| 92 |
then T'Base (LLF.Sqrt (LLF.T (X))) |
| 93 |
elsif T'Base'Digits > F.T'Digits |
| 94 |
then T'Base (LF.Sqrt (LF.T (X))) |
| 95 |
elsif T'Base'Digits > SF.T'Digits |
| 96 |
then T'Base (F.Sqrt (F.T (X))) |
| 97 |
else T'Base (SF.Sqrt (SF.T (X)))); |
| 98 |
|
| 99 |
function Log (X : T'Base) return T'Base |
| 100 |
is (if T'Base'Digits > LF.T'Digits |
| 101 |
then T'Base (LLF.Log (LLF.T (X))) |
| 102 |
elsif T'Base'Digits > F.T'Digits |
| 103 |
then T'Base (LF.Log (LF.T (X))) |
| 104 |
elsif T'Base'Digits > SF.T'Digits |
| 105 |
then T'Base (F.Log (F.T (X))) |
| 106 |
else T'Base (SF.Log (SF.T (X)))); |
| 107 |
|
| 108 |
function Acos (X : T'Base) return T'Base |
| 109 |
is (if T'Base'Digits > LF.T'Digits |
| 110 |
then T'Base (LLF.Acos (LLF.T (X))) |
| 111 |
elsif T'Base'Digits > F.T'Digits |
| 112 |
then T'Base (LF.Acos (LF.T (X))) |
| 113 |
elsif T'Base'Digits > SF.T'Digits |
| 114 |
then T'Base (F.Acos (F.T (X))) |
| 115 |
else T'Base (SF.Acos (SF.T (X)))); |
| 116 |
|
| 117 |
function Asin (X : T'Base) return T'Base |
| 118 |
is (if T'Base'Digits > LF.T'Digits |
| 119 |
then T'Base (LLF.Asin (LLF.T (X))) |
| 120 |
elsif T'Base'Digits > F.T'Digits |
| 121 |
then T'Base (LF.Asin (LF.T (X))) |
| 122 |
elsif T'Base'Digits > SF.T'Digits |
| 123 |
then T'Base (F.Asin (F.T (X))) |
| 124 |
else T'Base (SF.Asin (SF.T (X)))); |
| 125 |
|
| 126 |
function Atan (X : T'Base) return T'Base |
| 127 |
is (if T'Base'Digits > LF.T'Digits |
| 128 |
then T'Base (LLF.Atan (LLF.T (X))) |
| 129 |
elsif T'Base'Digits > F.T'Digits |
| 130 |
then T'Base (LF.Atan (LF.T (X))) |
| 131 |
elsif T'Base'Digits > SF.T'Digits |
| 132 |
then T'Base (F.Atan (F.T (X))) |
| 133 |
else T'Base (SF.Atan (SF.T (X)))); |
| 134 |
|
| 135 |
function Sinh (X : T'Base) return T'Base |
| 136 |
is (if T'Base'Digits > LF.T'Digits |
| 137 |
then T'Base (LLF.Sinh (LLF.T (X))) |
| 138 |
elsif T'Base'Digits > F.T'Digits |
| 139 |
then T'Base (LF.Sinh (LF.T (X))) |
| 140 |
elsif T'Base'Digits > SF.T'Digits |
| 141 |
then T'Base (F.Sinh (F.T (X))) |
| 142 |
else T'Base (SF.Sinh (SF.T (X)))); |
| 143 |
|
| 144 |
function Cosh (X : T'Base) return T'Base |
| 145 |
is (if T'Base'Digits > LF.T'Digits |
| 146 |
then T'Base (LLF.Cosh (LLF.T (X))) |
| 147 |
elsif T'Base'Digits > F.T'Digits |
| 148 |
then T'Base (LF.Cosh (LF.T (X))) |
| 149 |
elsif T'Base'Digits > SF.T'Digits |
| 150 |
then T'Base (F.Cosh (F.T (X))) |
| 151 |
else T'Base (SF.Cosh (SF.T (X)))); |
| 152 |
|
| 153 |
function Tanh (X : T'Base) return T'Base |
| 154 |
is (if T'Base'Digits > LF.T'Digits |
| 155 |
then T'Base (LLF.Tanh (LLF.T (X))) |
| 156 |
elsif T'Base'Digits > F.T'Digits |
| 157 |
then T'Base (LF.Tanh (LF.T (X))) |
| 158 |
elsif T'Base'Digits > SF.T'Digits |
| 159 |
then T'Base (F.Tanh (F.T (X))) |
| 160 |
else T'Base (SF.Tanh (SF.T (X)))); |
| 161 |
|
| 162 |
function Pow (X, Y : T'Base) return T'Base |
| 163 |
is (if T'Base'Digits > LF.T'Digits |
| 164 |
then T'Base (LLF.Pow (LLF.T (X), LLF.T (Y))) |
| 165 |
elsif T'Base'Digits > F.T'Digits |
| 166 |
then T'Base (LF.Pow (LF.T (X), LF.T (Y))) |
| 167 |
elsif T'Base'Digits > SF.T'Digits |
| 168 |
then T'Base (F.Pow (F.T (X), F.T (Y))) |
| 169 |
else T'Base (SF.Pow (SF.T (X), SF.T (Y)))); |
| 170 |
|
| 171 |
end Ada.Numerics.Aux_Generic_Float; |