D - How does one do exponentiation?
- Charles Hixson (9/9) Oct 02 2003 The only way I can see is via a log transform, and that seems clumsy.
- Maik Zumstrull (30/31) Oct 02 2003 D doesn't seem to have an operator for it, and it's not in the math
- Vathix (7/9) Oct 02 2003 This seems to be the only standard way:
- Charles Hixson (3/20) Oct 02 2003 Thanks. Considering the periginations I would appearantly have to
- Helmut Leitner (9/12) Oct 03 2003 Perhaps something like:
- Olaf Rogalsky (10/12) Oct 06 2003 extern (C) double pow(double b, double e);
- Sean L. Palmer (4/5) Oct 06 2003 Ideally we wouldn't have to depend on the C runtime library at all.
- Olaf Rogalsky (17/19) Oct 07 2003 Agreed! Personally I would like to see an internal '**' power operator,
The only way I can see is via a log transform, and that seems clumsy. ---- Alternative question: How does one return the hash value of a string? data.toHash doesn't work, and neither does string.getHash(data). I suspect one working answer will turn out to be something like: cast(Object [])data.toHash (I haven't yet tried that variation), but it seems like it should have a simpler answer. So what's the *proper* way to do it?
Oct 02 2003
Charles Hixson schrieb:The only way I can see is via a log transform, and that seems clumsy.D doesn't seem to have an operator for it, and it's not in the math library. (Or: I'm really dumb and overlooked it in the docs.) Maybe you can work with this: version (standalone) { import conv; import string; import stream; } bool isOdd(uint i) { return (i & 1) == 1; } uint exp(uint b, uint e) { if (e == 0) return 1; int r = 1; int y = b; while (e > 1) { if (isOdd(e)) r *= y; e = e >> 1; y *= y; } r *= y; return r; } version (standalone) { int main(char[][] args) { stream.stdout.writeLine(toString(exp(toUint(args[1]),toUint(args[2])))); return 0; } }
Oct 02 2003
"Charles Hixson" <charleshixsn earthlink.net> wrote in message news:blib9f$ke2$1 digitaldaemon.com...Alternative question: How does one return the hash value of a string?This seems to be the only standard way: import stream; uint dataHash = (new MemoryStream(cast(ubyte[])data)).toHash() Note: if data is a string literal and you don't want to use wchar's, cast it to char[] first.
Oct 02 2003
Vathix wrote:"Charles Hixson" <charleshixsn earthlink.net> wrote in message news:blib9f$ke2$1 digitaldaemon.com...Thanks. Considering the periginations I would appearantly have to go through to use exponentiation, that saves a bunch of trouble.Alternative question: How does one return the hash value of a string?This seems to be the only standard way: import stream; uint dataHash = (new MemoryStream(cast(ubyte[])data)).toHash() Note: if data is a string literal and you don't want to use wchar's, cast it to char[] first.
Oct 02 2003
Charles Hixson wrote:The only way I can see is via a log transform, and that seems clumsy.Perhaps something like: import math; double x,y,z; z=pow(x,y); (untested) -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Oct 03 2003
Charles Hixson wrote:The only way I can see is via a log transform, and that seems clumsy.extern (C) double pow(double b, double e); then link with -lm. -- +----------------------------------------------------------------------+ I Dr. Olaf Rogalsky Institut f. Theo. Physik I I I Tel.: 09131 8528440 Univ. Erlangen-Nuernberg I I Fax.: 09131 8528444 Staudtstrasse 7 B3 I I rogalsky theorie1.physik.uni-erlangen.de D-91058 Erlangen I +----------------------------------------------------------------------+
Oct 06 2003
Ideally we wouldn't have to depend on the C runtime library at all. Sean "Olaf Rogalsky" <olaf.rogalsky theorie1.physik.uni-erlangen.de> wrote in message news:3F81544F.A2386DA9 theorie1.physik.uni-erlangen.de...extern (C) double pow(double b, double e);
Oct 06 2003
"Sean L. Palmer" wrote:Ideally we wouldn't have to depend on the C runtime library at all.Agreed! Personally I would like to see an internal '**' power operator, overloaded for the basic numeric types. Why internal? `cause then the compiler could optimize constant expressions. Why a new '**' operator? Why not. It's concise, and eyecatching. The greatest disadvantage in the lisp family of languages is not having too many parentheses (for experienced programmers they become opaque), but the uniform syntax. Machines are good at parsing a language with uniform syntax, humans are not! Olaf -- +----------------------------------------------------------------------+ I Dr. Olaf Rogalsky Institut f. Theo. Physik I I I Tel.: 09131 8528440 Univ. Erlangen-Nuernberg I I Fax.: 09131 8528444 Staudtstrasse 7 B3 I I rogalsky theorie1.physik.uni-erlangen.de D-91058 Erlangen I +----------------------------------------------------------------------+
Oct 07 2003