From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a0310be41b671324 X-Google-Attributes: gid103376,public From: gauthier@alphainfo.unilim.fr (Michel Gauthier) Subject: Re: Float -> String conversion? Date: 1997/05/16 Message-ID: #1/1 X-Deja-AN: 241864753 References: <5lbj80$k4p$1@goanna.cs.rmit.edu.au> Organization: Universite de Limoges Newsgroups: comp.lang.ada Date: 1997-05-16T00:00:00+00:00 List-Id: In article <5lbj80$k4p$1@goanna.cs.rmit.edu.au>, Dale Stanbrough wrote: >> There are two ways that i know of that you can convert from a float >> to a string. >> >> Float'image - which is in x.xxxxExx format >> Ada.Float_Text_IO.Put >> >> ...but Text_IO is a rather large beast, and many people say >> that 'no one ever really uses text_io for _real_ work'. >> >> If this is the case, then how could one portably convert a float >> to a string? I agree with the idea that Ada.text_IO is harmful : - device-dependent, - didactically obsolete, - mixing of disk keeping and user interface. - using disk files implies opening 'standard' files. To work around the problem, I systematically add to all value (number-like) types a package for string<-> value conversion (the specification mimics predefined attributes and Text_IO subprograms) : generic type ITEM_TYPE is digits <> ; package STRINGS_FOR_FLOAT is function WIDTH return POSITIVE ; function IMAGE ( FROM : ITEM_TYPE ) return STRING ; function VALUE ( FROM : STRING ) return ITEM_TYPE ; procedure PUT ( TO : out STRING ; ITEM : in ITEM_TYPE ) ; procedure GET ( FROM : in STRING ; ITEM : out ITEM_TYPE ; LAST : out POSITIVE ) ; end STRINGS_FOR_FLOAT ; and a package for request-to-user operations : generic type FLOAT_TYPE is digits <> ; package REQUESTS . FOR_FLOAT is function REQUEST_A_FLOAT ( PROMPT : STRING ) return FLOAT_TYPE ; function REQUEST_A_FLOAT ( LOWER_BOUND : FLOAT_TYPE ; UPPER_BOUND : FLOAT_TYPE ; PROMPT : STRING ) return FLOAT_TYPE ; function REQUEST_A_FLOAT ( PROMPT : STRING ; EMPTY_LINE : FLOAT_TYPE ) return FLOAT_TYPE ; function REQUEST_A_FLOAT ( LOWER_BOUND : FLOAT_TYPE ; UPPER_BOUND : FLOAT_TYPE ; PROMPT : STRING ; EMPTY_LINE : FLOAT_TYPE ) return FLOAT_TYPE ; generic with function CONTROL ( APPLIED_TO : FLOAT_TYPE ) return BOOLEAN ; CONTROL_MESSAGE : STRING ; function REQUEST_A_FLOAT_WITHOUT_DEFAULT ( LOWER_BOUND : FLOAT_TYPE := FLOAT_TYPE ' FIRST ; UPPER_BOUND : FLOAT_TYPE := FLOAT_TYPE ' LAST ; PROMPT : STRING ) return FLOAT_TYPE ; generic with function CONTROL ( APPLIED_TO : FLOAT_TYPE ) return BOOLEAN ; CONTROL_MESSAGE : STRING ; function REQUEST_A_FLOAT_WITH_DEFAULT ( LOWER_BOUND : FLOAT_TYPE := FLOAT_TYPE ' FIRST ; UPPER_BOUND : FLOAT_TYPE := FLOAT_TYPE ' LAST ; PROMPT : STRING ; EMPTY_LINE : FLOAT_TYPE ) return FLOAT_TYPE ; end REQUESTS . FOR_FLOAT ; I planned also an any-device specification, but could not find time to complete coding it. I have similar packages for all classes of predefined numeric types, and for calendars, polynomials, sets,... (Requests is often a child of *.Strings in a generic context) Both specifications do not depend on Ada.Text_IO and are device-independent. Any relevant body can be coded, notably Requests for window-systems or Strings with different image or parser. Additionally, it would be useful to have a package containing only the part of Text_IO with File_Type parameters and no predefined 'file'. Hope this helps. Any comment appreciated. ---------- ---------- ---------- ---------- Michel Gauthier / Laboratoire d'informatique 123 avenue Albert Thomas / F-87060 Limoges telephone + 33 5 55 43 69 73 fax +33 5 55 43 69 77 ---------- ---------- ---------- ---------- Si l'an 2000 est pour vous un mysticisme stupide, utilisez la base 9 If you feel year 2000 a stupid mystic craze, use numeration base 9 ---------- ---------- ---------- ----------