Created
January 6, 2023 12:07
-
-
Save charlie5/e25d80d1d9c341624ee499a4cf0cb5e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with | |
ada.Text_IO, | |
ada.unchecked_Conversion; | |
-- procedure test | |
-- is | |
-- use ada.Text_IO; | |
-- type String_to_Float is (Behind, Close, Near, Far); | |
-- for String_to_Float use (Behind => -5, | |
-- Close => 5, | |
-- Near => 25, | |
-- Far => 55); | |
-- function to_Value (Key : in String) return Float | |
-- is | |
-- as_Enum : String_to_Float := String_to_Float'Value (Key); | |
-- function to_Integer is new ada.unchecked_Conversion (String_to_Float, Integer); | |
-- begin | |
-- return Float (to_Integer (as_Enum)); | |
-- end; | |
-- begin | |
-- put_Line ("Behind => " & to_Value ("BEHIND")'Image); | |
-- put_Line ("Close => " & to_Value ("Close" )'Image); | |
-- put_Line ("Far => " & to_Value ("far" )'Image); | |
-- end; | |
procedure test -- Float accuracy is 3 decimal places. | |
is | |
use ada.Text_IO; | |
type String_to_Float is (Behind, Close, Near, Far); | |
for String_to_Float use (Behind => -5_500, | |
Close => 5_678, | |
Near => 25_321, | |
Far => 55_123); | |
function to_Value (Key : in String) return Float | |
is | |
as_Enum : String_to_Float := String_to_Float'Value (Key); | |
function to_Integer is new ada.unchecked_Conversion (String_to_Float, Integer); | |
begin | |
return Float (to_Integer (as_Enum)) / 1_000.0; | |
end; | |
begin | |
put_Line ("Behind => " & to_Value ("BEHIND")'Image); | |
put_Line ("Close => " & to_Value ("Close" )'Image); | |
put_Line ("Far => " & to_Value ("far" )'Image); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment