* gcc.c-torture/execute/20020307-1.c: New test.
[official-gcc.git] / gcc / ada / i-cobol.adb
blob74b65b9e457af9cfe83262d78ef3d2755616869b
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- I N T E R F A C E S . C O B O L --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision: 1.14 $
10 -- --
11 -- Copyright (C) 1992-1999 Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- As a special exception, if other files instantiate generics from this --
25 -- unit, or you link this unit with other files to produce an executable, --
26 -- this unit does not by itself cause the resulting executable to be --
27 -- covered by the GNU General Public License. This exception does not --
28 -- however invalidate any other reasons why the executable file might be --
29 -- covered by the GNU Public License. --
30 -- --
31 -- GNAT was originally developed by the GNAT team at New York University. --
32 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
33 -- --
34 ------------------------------------------------------------------------------
36 -- The body of Interfaces.COBOL is implementation independent (i.e. the
37 -- same version is used with all versions of GNAT). The specialization
38 -- to a particular COBOL format is completely contained in the private
39 -- part ot the spec.
41 with Interfaces; use Interfaces;
42 with System; use System;
43 with Unchecked_Conversion;
45 package body Interfaces.COBOL is
47 -----------------------------------------------
48 -- Declarations for External Binary Handling --
49 -----------------------------------------------
51 subtype B1 is Byte_Array (1 .. 1);
52 subtype B2 is Byte_Array (1 .. 2);
53 subtype B4 is Byte_Array (1 .. 4);
54 subtype B8 is Byte_Array (1 .. 8);
55 -- Representations for 1,2,4,8 byte binary values
57 function To_B1 is new Unchecked_Conversion (Integer_8, B1);
58 function To_B2 is new Unchecked_Conversion (Integer_16, B2);
59 function To_B4 is new Unchecked_Conversion (Integer_32, B4);
60 function To_B8 is new Unchecked_Conversion (Integer_64, B8);
61 -- Conversions from native binary to external binary
63 function From_B1 is new Unchecked_Conversion (B1, Integer_8);
64 function From_B2 is new Unchecked_Conversion (B2, Integer_16);
65 function From_B4 is new Unchecked_Conversion (B4, Integer_32);
66 function From_B8 is new Unchecked_Conversion (B8, Integer_64);
67 -- Conversions from external binary to signed native binary
69 function From_B1U is new Unchecked_Conversion (B1, Unsigned_8);
70 function From_B2U is new Unchecked_Conversion (B2, Unsigned_16);
71 function From_B4U is new Unchecked_Conversion (B4, Unsigned_32);
72 function From_B8U is new Unchecked_Conversion (B8, Unsigned_64);
73 -- Conversions from external binary to unsigned native binary
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 function Binary_To_Decimal
80 (Item : Byte_Array;
81 Format : Binary_Format)
82 return Integer_64;
83 -- This function converts a numeric value in the given format to its
84 -- corresponding integer value. This is the non-generic implementation
85 -- of Decimal_Conversions.To_Decimal. The generic routine does the
86 -- final conversion to the fixed-point format.
88 function Numeric_To_Decimal
89 (Item : Numeric;
90 Format : Display_Format)
91 return Integer_64;
92 -- This function converts a numeric value in the given format to its
93 -- corresponding integer value. This is the non-generic implementation
94 -- of Decimal_Conversions.To_Decimal. The generic routine does the
95 -- final conversion to the fixed-point format.
97 function Packed_To_Decimal
98 (Item : Packed_Decimal;
99 Format : Packed_Format)
100 return Integer_64;
101 -- This function converts a packed value in the given format to its
102 -- corresponding integer value. This is the non-generic implementation
103 -- of Decimal_Conversions.To_Decimal. The generic routine does the
104 -- final conversion to the fixed-point format.
106 procedure Swap (B : in out Byte_Array; F : Binary_Format);
107 -- Swaps the bytes if required by the binary format F
109 function To_Display
110 (Item : Integer_64;
111 Format : Display_Format;
112 Length : Natural)
113 return Numeric;
114 -- This function converts the given integer value into display format,
115 -- using the given format, with the length in bytes of the result given
116 -- by the last parameter. This is the non-generic implementation of
117 -- Decimal_Conversions.To_Display. The conversion of the item from its
118 -- original decimal format to Integer_64 is done by the generic routine.
120 function To_Packed
121 (Item : Integer_64;
122 Format : Packed_Format;
123 Length : Natural)
124 return Packed_Decimal;
125 -- This function converts the given integer value into packed format,
126 -- using the given format, with the length in digits of the result given
127 -- by the last parameter. This is the non-generic implementation of
128 -- Decimal_Conversions.To_Display. The conversion of the item from its
129 -- original decimal format to Integer_64 is done by the generic routine.
131 function Valid_Numeric
132 (Item : Numeric;
133 Format : Display_Format)
134 return Boolean;
135 -- This is the non-generic implementation of Decimal_Conversions.Valid
136 -- for the display case.
138 function Valid_Packed
139 (Item : Packed_Decimal;
140 Format : Packed_Format)
141 return Boolean;
142 -- This is the non-generic implementation of Decimal_Conversions.Valid
143 -- for the packed case.
145 -----------------------
146 -- Binary_To_Decimal --
147 -----------------------
149 function Binary_To_Decimal
150 (Item : Byte_Array;
151 Format : Binary_Format)
152 return Integer_64
154 Len : constant Natural := Item'Length;
156 begin
157 if Len = 1 then
158 if Format in Binary_Unsigned_Format then
159 return Integer_64 (From_B1U (Item));
160 else
161 return Integer_64 (From_B1 (Item));
162 end if;
164 elsif Len = 2 then
165 declare
166 R : B2 := Item;
168 begin
169 Swap (R, Format);
171 if Format in Binary_Unsigned_Format then
172 return Integer_64 (From_B2U (R));
173 else
174 return Integer_64 (From_B2 (R));
175 end if;
176 end;
178 elsif Len = 4 then
179 declare
180 R : B4 := Item;
182 begin
183 Swap (R, Format);
185 if Format in Binary_Unsigned_Format then
186 return Integer_64 (From_B4U (R));
187 else
188 return Integer_64 (From_B4 (R));
189 end if;
190 end;
192 elsif Len = 8 then
193 declare
194 R : B8 := Item;
196 begin
197 Swap (R, Format);
199 if Format in Binary_Unsigned_Format then
200 return Integer_64 (From_B8U (R));
201 else
202 return Integer_64 (From_B8 (R));
203 end if;
204 end;
206 -- Length is not 1, 2, 4 or 8
208 else
209 raise Conversion_Error;
210 end if;
211 end Binary_To_Decimal;
213 ------------------------
214 -- Numeric_To_Decimal --
215 ------------------------
217 -- The following assumptions are made in the coding of this routine
219 -- The range of COBOL_Digits is compact and the ten values
220 -- represent the digits 0-9 in sequence
222 -- The range of COBOL_Plus_Digits is compact and the ten values
223 -- represent the digits 0-9 in sequence with a plus sign.
225 -- The range of COBOL_Minus_Digits is compact and the ten values
226 -- represent the digits 0-9 in sequence with a minus sign.
228 -- The COBOL_Minus_Digits set is disjoint from COBOL_Digits
230 -- These assumptions are true for all COBOL representations we know of.
232 function Numeric_To_Decimal
233 (Item : Numeric;
234 Format : Display_Format)
235 return Integer_64
237 pragma Unsuppress (Range_Check);
238 Sign : COBOL_Character := COBOL_Plus;
239 Result : Integer_64 := 0;
241 begin
242 if not Valid_Numeric (Item, Format) then
243 raise Conversion_Error;
244 end if;
246 for J in Item'Range loop
247 declare
248 K : constant COBOL_Character := Item (J);
250 begin
251 if K in COBOL_Digits then
252 Result := Result * 10 +
253 (COBOL_Character'Pos (K) -
254 COBOL_Character'Pos (COBOL_Digits'First));
256 elsif K in COBOL_Plus_Digits then
257 Result := Result * 10 +
258 (COBOL_Character'Pos (K) -
259 COBOL_Character'Pos (COBOL_Plus_Digits'First));
261 elsif K in COBOL_Minus_Digits then
262 Result := Result * 10 +
263 (COBOL_Character'Pos (K) -
264 COBOL_Character'Pos (COBOL_Minus_Digits'First));
265 Sign := COBOL_Minus;
267 -- Only remaining possibility is COBOL_Plus or COBOL_Minus
269 else
270 Sign := K;
271 end if;
272 end;
273 end loop;
275 if Sign = COBOL_Plus then
276 return Result;
277 else
278 return -Result;
279 end if;
281 exception
282 when Constraint_Error =>
283 raise Conversion_Error;
285 end Numeric_To_Decimal;
287 -----------------------
288 -- Packed_To_Decimal --
289 -----------------------
291 function Packed_To_Decimal
292 (Item : Packed_Decimal;
293 Format : Packed_Format)
294 return Integer_64
296 pragma Unsuppress (Range_Check);
297 Result : Integer_64 := 0;
298 Sign : constant Decimal_Element := Item (Item'Last);
300 begin
301 if not Valid_Packed (Item, Format) then
302 raise Conversion_Error;
303 end if;
305 case Packed_Representation is
306 when IBM =>
307 for J in Item'First .. Item'Last - 1 loop
308 Result := Result * 10 + Integer_64 (Item (J));
309 end loop;
311 if Sign = 16#0B# or else Sign = 16#0D# then
312 return -Result;
313 else
314 return +Result;
315 end if;
316 end case;
318 exception
319 when Constraint_Error =>
320 raise Conversion_Error;
321 end Packed_To_Decimal;
323 ----------
324 -- Swap --
325 ----------
327 procedure Swap (B : in out Byte_Array; F : Binary_Format) is
328 Little_Endian : constant Boolean :=
329 System.Default_Bit_Order = System.Low_Order_First;
331 begin
332 -- Return if no swap needed
334 case F is
335 when H | HU =>
336 if not Little_Endian then
337 return;
338 end if;
340 when L | LU =>
341 if Little_Endian then
342 return;
343 end if;
345 when N | NU =>
346 return;
347 end case;
349 -- Here a swap is needed
351 declare
352 Len : constant Natural := B'Length;
354 begin
355 for J in 1 .. Len / 2 loop
356 declare
357 Temp : constant Byte := B (J);
359 begin
360 B (J) := B (Len + 1 - J);
361 B (Len + 1 - J) := Temp;
362 end;
363 end loop;
364 end;
365 end Swap;
367 -----------------------
368 -- To_Ada (function) --
369 -----------------------
371 function To_Ada (Item : Alphanumeric) return String is
372 Result : String (Item'Range);
374 begin
375 for J in Item'Range loop
376 Result (J) := COBOL_To_Ada (Item (J));
377 end loop;
379 return Result;
380 end To_Ada;
382 ------------------------
383 -- To_Ada (procedure) --
384 ------------------------
386 procedure To_Ada
387 (Item : Alphanumeric;
388 Target : out String;
389 Last : out Natural)
391 Last_Val : Integer;
393 begin
394 if Item'Length > Target'Length then
395 raise Constraint_Error;
396 end if;
398 Last_Val := Target'First - 1;
399 for J in Item'Range loop
400 Last_Val := Last_Val + 1;
401 Target (Last_Val) := COBOL_To_Ada (Item (J));
402 end loop;
404 Last := Last_Val;
405 end To_Ada;
407 -------------------------
408 -- To_COBOL (function) --
409 -------------------------
411 function To_COBOL (Item : String) return Alphanumeric is
412 Result : Alphanumeric (Item'Range);
414 begin
415 for J in Item'Range loop
416 Result (J) := Ada_To_COBOL (Item (J));
417 end loop;
419 return Result;
420 end To_COBOL;
422 --------------------------
423 -- To_COBOL (procedure) --
424 --------------------------
426 procedure To_COBOL
427 (Item : String;
428 Target : out Alphanumeric;
429 Last : out Natural)
431 Last_Val : Integer;
433 begin
434 if Item'Length > Target'Length then
435 raise Constraint_Error;
436 end if;
438 Last_Val := Target'First - 1;
439 for J in Item'Range loop
440 Last_Val := Last_Val + 1;
441 Target (Last_Val) := Ada_To_COBOL (Item (J));
442 end loop;
444 Last := Last_Val;
445 end To_COBOL;
447 ----------------
448 -- To_Display --
449 ----------------
451 function To_Display
452 (Item : Integer_64;
453 Format : Display_Format;
454 Length : Natural)
455 return Numeric
457 Result : Numeric (1 .. Length);
458 Val : Integer_64 := Item;
460 procedure Convert (First, Last : Natural);
461 -- Convert the number in Val into COBOL_Digits, storing the result
462 -- in Result (First .. Last). Raise Conversion_Error if too large.
464 procedure Embed_Sign (Loc : Natural);
465 -- Used for the nonseparate formats to embed the appropriate sign
466 -- at the specified location (i.e. at Result (Loc))
468 procedure Convert (First, Last : Natural) is
469 J : Natural := Last;
471 begin
472 while J >= First loop
473 Result (J) :=
474 COBOL_Character'Val
475 (COBOL_Character'Pos (COBOL_Digits'First) +
476 Integer (Val mod 10));
477 Val := Val / 10;
479 if Val = 0 then
480 for K in First .. J - 1 loop
481 Result (J) := COBOL_Digits'First;
482 end loop;
484 return;
486 else
487 J := J - 1;
488 end if;
489 end loop;
491 raise Conversion_Error;
492 end Convert;
494 procedure Embed_Sign (Loc : Natural) is
495 Digit : Natural range 0 .. 9;
497 begin
498 Digit := COBOL_Character'Pos (Result (Loc)) -
499 COBOL_Character'Pos (COBOL_Digits'First);
501 if Item >= 0 then
502 Result (Loc) :=
503 COBOL_Character'Val
504 (COBOL_Character'Pos (COBOL_Plus_Digits'First) + Digit);
505 else
506 Result (Loc) :=
507 COBOL_Character'Val
508 (COBOL_Character'Pos (COBOL_Minus_Digits'First) + Digit);
509 end if;
510 end Embed_Sign;
512 -- Start of processing for To_Display
514 begin
515 case Format is
516 when Unsigned =>
517 if Val < 0 then
518 raise Conversion_Error;
519 else
520 Convert (1, Length);
521 end if;
523 when Leading_Separate =>
524 if Val < 0 then
525 Result (1) := COBOL_Minus;
526 Val := -Val;
527 else
528 Result (1) := COBOL_Plus;
529 end if;
531 Convert (2, Length);
533 when Trailing_Separate =>
534 if Val < 0 then
535 Result (Length) := COBOL_Minus;
536 Val := -Val;
537 else
538 Result (Length) := COBOL_Plus;
539 end if;
541 Convert (1, Length - 1);
543 when Leading_Nonseparate =>
544 Val := abs Val;
545 Convert (1, Length);
546 Embed_Sign (1);
548 when Trailing_Nonseparate =>
549 Val := abs Val;
550 Convert (1, Length);
551 Embed_Sign (Length);
553 end case;
555 return Result;
556 end To_Display;
558 ---------------
559 -- To_Packed --
560 ---------------
562 function To_Packed
563 (Item : Integer_64;
564 Format : Packed_Format;
565 Length : Natural)
566 return Packed_Decimal
568 Result : Packed_Decimal (1 .. Length);
569 Val : Integer_64;
571 procedure Convert (First, Last : Natural);
572 -- Convert the number in Val into a sequence of Decimal_Element values,
573 -- storing the result in Result (First .. Last). Raise Conversion_Error
574 -- if the value is too large to fit.
576 procedure Convert (First, Last : Natural) is
577 J : Natural := Last;
579 begin
580 while J >= First loop
581 Result (J) := Decimal_Element (Val mod 10);
583 Val := Val / 10;
585 if Val = 0 then
586 for K in First .. J - 1 loop
587 Result (K) := 0;
588 end loop;
590 return;
592 else
593 J := J - 1;
594 end if;
595 end loop;
597 raise Conversion_Error;
598 end Convert;
600 -- Start of processing for To_Packed
602 begin
603 case Packed_Representation is
604 when IBM =>
605 if Format = Packed_Unsigned then
606 if Item < 0 then
607 raise Conversion_Error;
608 else
609 Result (Length) := 16#F#;
610 Val := Item;
611 end if;
613 elsif Item >= 0 then
614 Result (Length) := 16#C#;
615 Val := Item;
617 else -- Item < 0
618 Result (Length) := 16#D#;
619 Val := -Item;
620 end if;
622 Convert (1, Length - 1);
623 return Result;
624 end case;
625 end To_Packed;
627 -------------------
628 -- Valid_Numeric --
629 -------------------
631 function Valid_Numeric
632 (Item : Numeric;
633 Format : Display_Format)
634 return Boolean
636 begin
637 -- All character positions except first and last must be Digits.
638 -- This is true for all the formats.
640 for J in Item'First + 1 .. Item'Last - 1 loop
641 if Item (J) not in COBOL_Digits then
642 return False;
643 end if;
644 end loop;
646 case Format is
647 when Unsigned =>
648 return Item (Item'First) in COBOL_Digits
649 and then Item (Item'Last) in COBOL_Digits;
651 when Leading_Separate =>
652 return (Item (Item'First) = COBOL_Plus or else
653 Item (Item'First) = COBOL_Minus)
654 and then Item (Item'Last) in COBOL_Digits;
656 when Trailing_Separate =>
657 return Item (Item'First) in COBOL_Digits
658 and then
659 (Item (Item'Last) = COBOL_Plus or else
660 Item (Item'Last) = COBOL_Minus);
662 when Leading_Nonseparate =>
663 return (Item (Item'First) in COBOL_Plus_Digits or else
664 Item (Item'First) in COBOL_Minus_Digits)
665 and then Item (Item'Last) in COBOL_Digits;
667 when Trailing_Nonseparate =>
668 return Item (Item'First) in COBOL_Digits
669 and then
670 (Item (Item'Last) in COBOL_Plus_Digits or else
671 Item (Item'Last) in COBOL_Minus_Digits);
673 end case;
674 end Valid_Numeric;
676 ------------------
677 -- Valid_Packed --
678 ------------------
680 function Valid_Packed
681 (Item : Packed_Decimal;
682 Format : Packed_Format)
683 return Boolean
685 begin
686 case Packed_Representation is
687 when IBM =>
688 for J in Item'First .. Item'Last - 1 loop
689 if Item (J) > 9 then
690 return False;
691 end if;
692 end loop;
694 -- For unsigned, sign digit must be F
696 if Format = Packed_Unsigned then
697 return Item (Item'Last) = 16#F#;
700 -- For signed, accept all standard and non-standard signs
702 else
703 return Item (Item'Last) in 16#A# .. 16#F#;
704 end if;
705 end case;
706 end Valid_Packed;
708 -------------------------
709 -- Decimal_Conversions --
710 -------------------------
712 package body Decimal_Conversions is
714 ---------------------
715 -- Length (binary) --
716 ---------------------
718 -- Note that the tests here are all compile time tests
720 function Length (Format : Binary_Format) return Natural is
721 begin
722 if Num'Digits <= 2 then
723 return 1;
725 elsif Num'Digits <= 4 then
726 return 2;
728 elsif Num'Digits <= 9 then
729 return 4;
731 else -- Num'Digits in 10 .. 18
732 return 8;
733 end if;
734 end Length;
736 ----------------------
737 -- Length (display) --
738 ----------------------
740 function Length (Format : Display_Format) return Natural is
741 begin
742 if Format = Leading_Separate or else Format = Trailing_Separate then
743 return Num'Digits + 1;
744 else
745 return Num'Digits;
746 end if;
747 end Length;
749 ---------------------
750 -- Length (packed) --
751 ---------------------
753 -- Note that the tests here are all compile time checks
755 function Length
756 (Format : Packed_Format)
757 return Natural
759 begin
760 case Packed_Representation is
761 when IBM =>
762 return (Num'Digits + 2) / 2 * 2;
763 end case;
764 end Length;
766 ---------------
767 -- To_Binary --
768 ---------------
770 function To_Binary
771 (Item : Num;
772 Format : Binary_Format)
773 return Byte_Array
775 begin
776 -- Note: all these tests are compile time tests
778 if Num'Digits <= 2 then
779 return To_B1 (Integer_8'Integer_Value (Item));
781 elsif Num'Digits <= 4 then
782 declare
783 R : B2 := To_B2 (Integer_16'Integer_Value (Item));
785 begin
786 Swap (R, Format);
787 return R;
788 end;
790 elsif Num'Digits <= 9 then
791 declare
792 R : B4 := To_B4 (Integer_32'Integer_Value (Item));
794 begin
795 Swap (R, Format);
796 return R;
797 end;
799 else -- Num'Digits in 10 .. 18
800 declare
801 R : B8 := To_B8 (Integer_64'Integer_Value (Item));
803 begin
804 Swap (R, Format);
805 return R;
806 end;
807 end if;
809 exception
810 when Constraint_Error =>
811 raise Conversion_Error;
812 end To_Binary;
814 ---------------------------------
815 -- To_Binary (internal binary) --
816 ---------------------------------
818 function To_Binary (Item : Num) return Binary is
819 pragma Unsuppress (Range_Check);
820 begin
821 return Binary'Integer_Value (Item);
823 exception
824 when Constraint_Error =>
825 raise Conversion_Error;
826 end To_Binary;
828 -------------------------
829 -- To_Decimal (binary) --
830 -------------------------
832 function To_Decimal
833 (Item : Byte_Array;
834 Format : Binary_Format)
835 return Num
837 pragma Unsuppress (Range_Check);
839 begin
840 return Num'Fixed_Value (Binary_To_Decimal (Item, Format));
842 exception
843 when Constraint_Error =>
844 raise Conversion_Error;
845 end To_Decimal;
847 ----------------------------------
848 -- To_Decimal (internal binary) --
849 ----------------------------------
851 function To_Decimal (Item : Binary) return Num is
852 pragma Unsuppress (Range_Check);
854 begin
855 return Num'Fixed_Value (Item);
857 exception
858 when Constraint_Error =>
859 raise Conversion_Error;
860 end To_Decimal;
862 --------------------------
863 -- To_Decimal (display) --
864 --------------------------
866 function To_Decimal
867 (Item : Numeric;
868 Format : Display_Format)
869 return Num
871 pragma Unsuppress (Range_Check);
873 begin
874 return Num'Fixed_Value (Numeric_To_Decimal (Item, Format));
876 exception
877 when Constraint_Error =>
878 raise Conversion_Error;
879 end To_Decimal;
881 ---------------------------------------
882 -- To_Decimal (internal long binary) --
883 ---------------------------------------
885 function To_Decimal (Item : Long_Binary) return Num is
886 pragma Unsuppress (Range_Check);
888 begin
889 return Num'Fixed_Value (Item);
891 exception
892 when Constraint_Error =>
893 raise Conversion_Error;
894 end To_Decimal;
896 -------------------------
897 -- To_Decimal (packed) --
898 -------------------------
900 function To_Decimal
901 (Item : Packed_Decimal;
902 Format : Packed_Format)
903 return Num
905 pragma Unsuppress (Range_Check);
907 begin
908 return Num'Fixed_Value (Packed_To_Decimal (Item, Format));
910 exception
911 when Constraint_Error =>
912 raise Conversion_Error;
913 end To_Decimal;
915 ----------------
916 -- To_Display --
917 ----------------
919 function To_Display
920 (Item : Num;
921 Format : Display_Format)
922 return Numeric
924 pragma Unsuppress (Range_Check);
926 begin
927 return
928 To_Display
929 (Integer_64'Integer_Value (Item),
930 Format,
931 Length (Format));
933 exception
934 when Constraint_Error =>
935 raise Conversion_Error;
936 end To_Display;
938 --------------------
939 -- To_Long_Binary --
940 --------------------
942 function To_Long_Binary (Item : Num) return Long_Binary is
943 pragma Unsuppress (Range_Check);
945 begin
946 return Long_Binary'Integer_Value (Item);
948 exception
949 when Constraint_Error =>
950 raise Conversion_Error;
951 end To_Long_Binary;
953 ---------------
954 -- To_Packed --
955 ---------------
957 function To_Packed
958 (Item : Num;
959 Format : Packed_Format)
960 return Packed_Decimal
962 pragma Unsuppress (Range_Check);
964 begin
965 return
966 To_Packed
967 (Integer_64'Integer_Value (Item),
968 Format,
969 Length (Format));
971 exception
972 when Constraint_Error =>
973 raise Conversion_Error;
974 end To_Packed;
976 --------------------
977 -- Valid (binary) --
978 --------------------
980 function Valid
981 (Item : Byte_Array;
982 Format : Binary_Format)
983 return Boolean
985 Val : Num;
987 begin
988 Val := To_Decimal (Item, Format);
989 return True;
991 exception
992 when Conversion_Error =>
993 return False;
994 end Valid;
996 ---------------------
997 -- Valid (display) --
998 ---------------------
1000 function Valid
1001 (Item : Numeric;
1002 Format : Display_Format)
1003 return Boolean
1005 begin
1006 return Valid_Numeric (Item, Format);
1007 end Valid;
1009 --------------------
1010 -- Valid (packed) --
1011 --------------------
1013 function Valid
1014 (Item : Packed_Decimal;
1015 Format : Packed_Format)
1016 return Boolean
1018 begin
1019 return Valid_Packed (Item, Format);
1020 end Valid;
1022 end Decimal_Conversions;
1024 end Interfaces.COBOL;