* Collection of 2500+ links about Object-Orientation - interested ?
@ 1996-11-05 0:00 Manfred Schneider
1996-11-07 0:00 ` Leading zeros with Int_IO.Put()? Or another package? John Herro
0 siblings, 1 reply; 4+ messages in thread
From: Manfred Schneider @ 1996-11-05 0:00 UTC (permalink / raw)
Hello,
are you interested in a collection of more than 2500 links
about object-orientation? No ads, fast and free access!
Main topics of the collection are:
o General Information and Links
o Distributed Objects, Corba, OpenDoc, ActiveX / OLE,
Object Request Brokers, Business Objects
o OOA/OOD Methods and Tools, Diagram Layout
o Languages, Ada, Delphi, Eiffel, Java, JavaScript,
Python, Smalltalk, VBScript, Visual Basic, Visual C++
o Databases, OO DBMS, OR DBMS
o Patterns, Libraries, Frameworks
o Metrics, Reuse, Testing, Numerics
o Services and Companies
The collection runs on a server in Heidelberg, Germany.
Mirrors are available for faster access from other contries.
URL of original site:
o http://www.rhein-neckar.de/~cetus/software.html
URLs of mirrors:
o Australia, Melbourne
http://www.csse.swin.edu.au/manfred/software.html
o Brazil, RS, Porto Alegre
http://www.intuitive.com.br/cetus/software.html
o USA, IL, Chicago
http://www.objenv.com/cetus/software.html
o USA, UT, Provo
http://mini.net/cetus/software.html
I am still looking for sites in ASIA, which would like to mirror
Cetus. So visitors from the APA region have easier access
to the link collection.
Moreover I am interested in further URLs about ...
o diagram layout
o frameworks
o metrics
o reuse
o testing
If you are interested in mirroring or know some URLs
please let me know.
Manfred
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Leading zeros with Int_IO.Put()? Or another package?
1996-11-07 0:00 ` Leading zeros with Int_IO.Put()? Or another package? John Herro
@ 1996-11-07 0:00 ` James Rogers
1996-11-07 0:00 ` Robert Dewar
1 sibling, 0 replies; 4+ messages in thread
From: James Rogers @ 1996-11-07 0:00 UTC (permalink / raw)
The following certainly does not qualify for the shortest solution,
but it does cover a multitude of cases.
---------------------------------------------------------------------------
-- Utility to print zero-filled strings of integer values.
---------------------------------------------------------------------------
package zero_fill is
procedure zput (Item : in Integer;
Width : in Natural := 2);
function zput ( Item : in Integer;
Width : in Natural := 2) return string;
end zero_fill;
---------------------------------------------------------------------------
-- Utility to print zero-filled strings of integer values.
---------------------------------------------------------------------------
with Ada.Text_IO;
with Ada.Numerics.Aux;
package body zero_fill is
Package tio renames Ada.Text_IO;
Package int_io is new tio.integer_io(integer);
Package naux renames Ada.Numerics.Aux;
procedure zput (Item : in Integer;
Width : in Natural := 2) is
num_digits : long_float;
Length : Positive;
calc_digits : Natural;
begin
num_digits := naux.log(long_float(Item)) / naux.log(10.0);
begin
calc_digits := natural(long_float'floor(num_digits)) + 1;
exception
when constraint_error =>
tio.put_line("Conversion Error.");
raise;
end;
if calc_digits < Width then
Length := Natural(Num_Digits) + 1;
else
Length := Width;
end if;
declare
out_string : string(1..Length);
begin
int_io.put(out_string, Item);
for Index in reverse out_string'Range loop
if out_string(Index) not in '0'..'9' then
out_string(Index) := '0';
end if;
end loop;
tio.put(out_string);
end;
end zput;
function zput ( Item : in Integer;
Width : in Natural := 2) return string is
num_digits : long_float;
Length : Positive;
begin
num_digits := naux.log(long_float(Item)) / naux.log(10.0);
if Natural(num_digits) + 1 < Width then
Length := Natural(Num_Digits) + 1;
else
Length := Width;
end if;
declare
out_string : string(1..Length);
begin
int_io.put(out_string, Item);
for Index in reverse out_string'Range loop
if out_string(Index) not in '0'..'9' then
out_string(Index) := '0';
end if;
end loop;
return out_string;
end;
end zput;
end zero_fill;
--
Jim Rogers
*************************************************************
Team Ada
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Leading zeros with Int_IO.Put()? Or another package?
1996-11-05 0:00 Collection of 2500+ links about Object-Orientation - interested ? Manfred Schneider
@ 1996-11-07 0:00 ` John Herro
1996-11-07 0:00 ` James Rogers
1996-11-07 0:00 ` Robert Dewar
0 siblings, 2 replies; 4+ messages in thread
From: John Herro @ 1996-11-07 0:00 UTC (permalink / raw)
baldwin@netcom.com (J.D. Baldwin) wrote:
> if (MINUTE <= 9) then
> Int_IO.Put(0, 0);
> end if;
> Int_IO.Put(MINUTE,0);
> ... is there a better way to pad out integers
> with leading zeros?
I don't know if this way is "better," but here's how I force leading zeros
when I know the number is never too large for the desired width and the
number is never negative. (In this example, Minute is never more than two
digits and never negative). Let's call the desired width W. Add the
constant 10**W, take the 'Image, which will always have exactly W+2
characters, and select the last W characters of the result. For example,
if Minute = 4 and is of type Integer, then Integer'Image(104) is " 104"
and the last two characters are "04". In your code, you COULD replace
four lines with
Ada.Text_IO.Put(Integer'Image(100 + Minute)(3 .. 4));
This technique works only when W is small enough that 10**W plus the
largest number you're going to handle doesn't overflow. For example, if
the number you're outputting is an Integer and Integer'Last is
2_147_483_647 (ten digits), then W can be at most nine to avoid overflow.
Within that limit, this technique can force multiple leading zeros to any
desired width.
Whether this way of forcing leading zeros is "better" is certainly
debatable. All I can say for certain is that it's fewer lines.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor
-----
ANSWER: "Close cover before striking."
QUESTION: What did the labor union leader say to the sewer workers?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Leading zeros with Int_IO.Put()? Or another package?
1996-11-07 0:00 ` Leading zeros with Int_IO.Put()? Or another package? John Herro
1996-11-07 0:00 ` James Rogers
@ 1996-11-07 0:00 ` Robert Dewar
1 sibling, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1996-11-07 0:00 UTC (permalink / raw)
John Herro says
"Whether this way of forcing leading zeros is "better" is certainly
debatable. All I can say for certain is that it's fewer lines."
That of course is NOT a criterion (and you don't say it is :-)
This is a place where CLEARLY there is a missing abstraction (Put with
leading zeros), and it seems obvious that you fix this in the way that
you always do abstraction extension, you create an appropriate abstraction
and use it. If it is useful enough, hopefully it gets to be widely available.
Note that if you do want to construct on the fly, a much clearer way is to
use the string routines from the string packages, which have padding
capabilities.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1996-11-07 0:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-05 0:00 Collection of 2500+ links about Object-Orientation - interested ? Manfred Schneider
1996-11-07 0:00 ` Leading zeros with Int_IO.Put()? Or another package? John Herro
1996-11-07 0:00 ` James Rogers
1996-11-07 0:00 ` Robert Dewar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox