[fpc-pascal] two small ?s - high(real) and nearest 2^x
David Emerson
dle3ab at angelbase.com
Sun Oct 11 02:51:33 CEST 2009
Thanks, guys!
hrm, I am a little disappointed to realize that, although I'm on a
32-bit system, 'real' maps to 'double' rather than 'single' ... and it
is a bit slower, too. So I guess I'll use single for now.
an fpc bsr function would be nice, but I'm gonna stick with compatible
code.
I do realize that allocating by doubling size is memory intensive, but
it's just for the rapid growth part-- once the array is populated, I
shrink it down to its precise size.
Cheers,
David.
On Sat 10 Oct 2009, David Emerson wrote:
> 1. Is there a way to get the highest and lowest real values? I can do
> high(longint) but high(real) gives me an error. Also of interest is a
> low(real) value (-m * 10^n) as distinct from the smallest real value
> (m * 10^-n)
>
> 2. For the purposes of reserving memory in block sizes that can be
> easily reallocated, I like to use powers of two. So if I have, e.g., a
> dynamic array, I might start with a size of 1024 and then double it
> when it hits capacity. Hopefully this smoothes memory management, as I
> am using a lot of memory...
>
> Anyway, what I'd like is a simple function that can quickly identify
the
> next power-of-two larger than an arbitrary number. So if I feed the
> function 472, it will return 512. Thus far I haven't been able to
> figure out how to do this without a big if-then-else nest. Is there
> some clever way to request that the processor return the position of
> the leftmost '1' in 00101101?
>
> Thanks!
> ~David.
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list