comp.lang.ada
 help / color / mirror / Atom feed
* Re: number bases
  1999-11-01  0:00 number bases G
  1999-11-01  0:00 ` tmoran
  1999-11-01  0:00 ` Robert Dewar
@ 1999-11-01  0:00 ` JP Thornley
  1999-11-02  0:00   ` Robert Dewar
  1999-11-01  0:00 ` Ted Dennison
  1999-11-02  0:00 ` Daryle Walker
  4 siblings, 1 reply; 10+ messages in thread
From: JP Thornley @ 1999-11-01  0:00 UTC (permalink / raw)


In article: <381D4C88.B5E8BBE7@interact.net.au>  G 
<Dizzy@interact.net.au> writes:
> If someone decides to represent all or the majority of integers in a
> program unit with base 2
> or
> 16
> - does this in any way optimise the code.  Which is to say - does it
> take less space in memory and is it more efficient (does it run 
faster)
> to represent integers (floats, whatever) in a form closer to the 
machine
> architecture/structure (i.e. binary) ?
> 

(This may not be relevant to the question, but...) I recently wrote an 
infinite (size and precision) Rational number package, where the radix 
used for the dividend and divisor could be anywhere between 2 and 45_000 
(radix**2 has to be less than Max_Int). I tried it with a few different 
values, and the clear winner on speed was a radix of 256. (I don't know 
about storage). This was Gnat 3.10 on Win95.

Cheers,

Phil

-- 
------------------------------------------------------------------------
| JP Thornley    EMail jpt@diphi.demon.co.uk                           |
|                      phil.thornley@acm.org                           |
------------------------------------------------------------------------






^ permalink raw reply	[flat|nested] 10+ messages in thread

* number bases
@ 1999-11-01  0:00 G
  1999-11-01  0:00 ` tmoran
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: G @ 1999-11-01  0:00 UTC (permalink / raw)


Hi.

I don't have enough time to study Ada full time because I am too busy
doing websites for non-profits, welfare orgs etc.

However - my occasional series of silly and irrelevant programming
questions concerning Ada continues:

If someone decides to represent all or the majority of integers in a
program unit with base 2
or
16
- does this in any way optimise the code.  Which is to say - does it
take less space in memory and is it more efficient (does it run faster)
to represent integers (floats, whatever) in a form closer to the machine
architecture/structure (i.e. binary) ?

Puh-leeze.

-Thanks
-G





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: number bases
  1999-11-01  0:00 number bases G
  1999-11-01  0:00 ` tmoran
@ 1999-11-01  0:00 ` Robert Dewar
  1999-11-01  0:00 ` JP Thornley
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Robert Dewar @ 1999-11-01  0:00 UTC (permalink / raw)


In article <381D4C88.B5E8BBE7@interact.net.au>,
  G <Dizzy@interact.net.au> wrote:
> If someone decides to represent all or the majority of
integers in a
> program unit with base 2
> or
> 16

are you talking about Machine_Radix here???

> - does this in any way optimise the code.  Which is to say -
does it
> take less space in memory and is it more efficient (does it
run faster)
> to represent integers (floats, whatever) in a form closer to
the machine
> architecture/structure (i.e. binary) ?


This is an implementation and not a language question, obviously
specifying a machine radix of 10 on a non-decimal machines is
likely to degrade performance if the implementation follows
the specification (it is not required to).


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: number bases
  1999-11-01  0:00 number bases G
                   ` (2 preceding siblings ...)
  1999-11-01  0:00 ` JP Thornley
@ 1999-11-01  0:00 ` Ted Dennison
  1999-11-02  0:00 ` Daryle Walker
  4 siblings, 0 replies; 10+ messages in thread
From: Ted Dennison @ 1999-11-01  0:00 UTC (permalink / raw)


In article <381D4C88.B5E8BBE7@interact.net.au>,
  G <Dizzy@interact.net.au> wrote:
> If someone decides to represent all or the majority of integers in a
> program unit with base 2
> or
> 16
> - does this in any way optimise the code.  Which is to say - does it
> take less space in memory and is it more efficient (does it run
faster)
> to represent integers (floats, whatever) in a form closer to the
machine
> architecture/structure (i.e. binary) ?

I'm not sure what you are asking here. If you mean does
   Fred : constant Integer := 2#1011#;
take less space or time at runtime than
   Fred : constant Integer := 11;

the answer is no. They are both translated into the exact same thing at
compile time. This is the same answer you'd get if you were asking the
same question about a C or Java compiler.

--
T.E.D.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: number bases
  1999-11-01  0:00 number bases G
@ 1999-11-01  0:00 ` tmoran
  1999-11-02  0:00   ` Robert Dewar
  1999-11-01  0:00 ` Robert Dewar
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: tmoran @ 1999-11-01  0:00 UTC (permalink / raw)


>If someone decides to represent all or the majority of integers in a
>program unit with base 2 or 16 - does this in any way optimise the code.
  This is not a decision normally made by the programmer, but rather
by the compiler.  For a binary machine a compiler will normally
use binary representations.  For a decimal machine (not many of
those around these days), it would probably use decimal.  The people
who write production compilers are extremely familiar with the
machine they are generating code for, and will use optimized
techniques - or nobody will buy their compiler.

>I don't have enough time to study Ada full time because I am too busy
  Spend three minutes concentrating on reading the beginning of an
intro to programming book, and you'll save hours of wondering, as well
as three minutes of newsgroup posting and reading time.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: number bases
  1999-11-02  0:00   ` Robert Dewar
@ 1999-11-02  0:00     ` tmoran
  0 siblings, 0 replies; 10+ messages in thread
From: tmoran @ 1999-11-02  0:00 UTC (permalink / raw)


>Really? Then what is your interpretation of
>
>    for Money'Machine_Radix use 10;
>
>This by the way, is cut and pasted from the Ada reference
>manual, F.1(4).
  F.1(4) refers to decimal types (see F.1(1)).  Since the
original question asked about representing integers and
floats in binary, I don't think the original questioner
was asking about F.1




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: number bases
  1999-11-01  0:00 number bases G
                   ` (3 preceding siblings ...)
  1999-11-01  0:00 ` Ted Dennison
@ 1999-11-02  0:00 ` Daryle Walker
  1999-11-03  0:00   ` Robert Dewar
  4 siblings, 1 reply; 10+ messages in thread
From: Daryle Walker @ 1999-11-02  0:00 UTC (permalink / raw)


G <Dizzy@interact.net.au> wrote:

> I don't have enough time to study Ada full time because I am too busy
> doing websites for non-profits, welfare orgs etc.

Well, you can't expect to be good in Ada without some effort.
Newsgroups can only do so much.

> If someone decides to represent all or the majority of integers in a
> program unit with base 2 or 16 - does this in any way optimise the code.
> Which is to say - does it take less space in memory and is it more
> efficient (does it run faster) to represent integers (floats, whatever) in
> a form closer to the machine architecture/structure (i.e. binary) ?

What base you use makes no difference to the runtime performance.  The
representation you typed is converted to the same independent format by
the compiler, so the differences between bases goes away.  This applies
to the built-in types; an user-defined type may keep base information,
i.e. store its value in place-value notation, which would be
runtime-affected by the radix chosen.


-- 
Daryle Walker
Video Game, Mac, and Internet Junkie
dwalker07 AT snet DOT net




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: number bases
  1999-11-01  0:00 ` tmoran
@ 1999-11-02  0:00   ` Robert Dewar
  1999-11-02  0:00     ` tmoran
  0 siblings, 1 reply; 10+ messages in thread
From: Robert Dewar @ 1999-11-02  0:00 UTC (permalink / raw)


In article <8hkT3.225$cn1.1641@typhoon-sf.snfc21.pbi.net>,
  tmoran@bix.com wrote:
> This is not a decision normally made by the programmer, but
> rather by the compiler.

Really? Then what is your interpretation of

    for Money'Machine_Radix use 10;

This by the way, is cut and pasted from the Ada reference
manual, F.1(4).



Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: number bases
  1999-11-01  0:00 ` JP Thornley
@ 1999-11-02  0:00   ` Robert Dewar
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Dewar @ 1999-11-02  0:00 UTC (permalink / raw)


In article <860624474wnr@diphi.demon.co.uk>,
  jpt@diphi.demon.co.uk wrote:
 where the radix
> used for the dividend and divisor could be anywhere between 2
and 45_000
> (radix**2 has to be less than Max_Int). I tried it with a few
different
> values, and the clear winner on speed was a radix of 256. (I
don't know
> about storage). This was Gnat 3.10 on Win95.

Of course the efficient way to do multiple precision on
a machine with k-bit words is to use a radix of 2**k, but
higher level languages make this approach hard. Multiple
precision integer arithmetic is one of the few things I
know that is FAR easier to program in machine language than
in typical high level languages (which do not give convenient
access to the necessary primitives, namely the carry flag, and
double length products and dividends).


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: number bases
  1999-11-02  0:00 ` Daryle Walker
@ 1999-11-03  0:00   ` Robert Dewar
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Dewar @ 1999-11-03  0:00 UTC (permalink / raw)


In article <1e0nbtb.i50iir1e6b3zhN%dwalker07@snet.net.invalid>,
  dwalker07@snet.net.invalid (Daryle Walker) wrote:
t expect to be good in Ada without some effort.
> Newsgroups can only do so much.
>
> What base you use makes no difference to the runtime
> performance.

Again you are assuming that the question is about number bases
in integer literals. Yes, that might be the case, it is always
hard to guess in the absence of a clear report. But the question
makes sense only if it is about Machine_Radix.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~1999-11-03  0:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-01  0:00 number bases G
1999-11-01  0:00 ` tmoran
1999-11-02  0:00   ` Robert Dewar
1999-11-02  0:00     ` tmoran
1999-11-01  0:00 ` Robert Dewar
1999-11-01  0:00 ` JP Thornley
1999-11-02  0:00   ` Robert Dewar
1999-11-01  0:00 ` Ted Dennison
1999-11-02  0:00 ` Daryle Walker
1999-11-03  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