www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - exponent operator/library function

reply Michael P. <baseball.mjp gmail.com> writes:
Quick question: What do you have to use to do something like, 10 to the power
of 3? Something in std.math, a built-in operator?
That's all.

-Michael P.
Aug 04 2008
parent reply BCS <ao pathlink.com> writes:
Reply to Michael P.,

 Quick question: What do you have to use to do something like, 10 to
 the power of 3? Something in std.math, a built-in operator?
 
 That's all.
 
 -Michael P.
 
iirc its.math.pow(base,exp);
Aug 04 2008
parent reply Michael P. <baseball.mjp gmail.com> writes:
BCS Wrote:

 Reply to Michael P.,
 
 Quick question: What do you have to use to do something like, 10 to
 the power of 3? Something in std.math, a built-in operator?
 
 That's all.
 
 -Michael P.
 
iirc its.math.pow(base,exp);
Unfortunately, those didn't work( because of type issues). So I made my own integer one. :) Anyways, somewhat unrelated question: I have attached a file that includes a simple program that I've made for keeping the brain fit, with memory. I've also made one that let's you do simple addition. :D Anyways, everything is compiling fine, but I get an ArrayOutOfBounds error on line 125 or something. Okay, it's function createArray, which is called by memoryTest. Line 114, 115. The file is attached. Does anyone know I'm getting these array errors? -Michael P.
Aug 04 2008
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to Michael P.,

 Anyways, everything is compiling fine, but I get an ArrayOutOfBounds
 error on line 125 or something.
 
line 125: for ( int i = arrayToConvert.length; i > 0; i-- ) that should be: for ( int i = arrayToConvert.length - 1; i > 0; i-- ) this is because arr[arr.length] is the elemant after the last element.
Aug 04 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"BCS" <ao pathlink.com> wrote in message 
news:55391cb32ff418cac458bee9a3c8 news.digitalmars.com...
 Reply to Michael P.,

 Anyways, everything is compiling fine, but I get an ArrayOutOfBounds
 error on line 125 or something.
line 125: for ( int i = arrayToConvert.length; i > 0; i-- ) that should be: for ( int i = arrayToConvert.length - 1; i > 0; i-- )
You mean i >= 0, I suppose. ;)
 this is because arr[arr.length] is the elemant after the last element.
No offense BCS, but for someone so well-spoken and intelligent, I'm kind of shocked at how poor/inconsistent your spelling is. "elemant" and "element" in the same sentence?
Aug 04 2008
parent BCS <ao pathlink.com> writes:
Reply to Jarrett,

 "BCS" <ao pathlink.com> wrote in message
 news:55391cb32ff418cac458bee9a3c8 news.digitalmars.com...
 
 Reply to Michael P.,
 
 Anyways, everything is compiling fine, but I get an ArrayOutOfBounds
 error on line 125 or something.
 
line 125: for ( int i = arrayToConvert.length; i > 0; i-- ) that should be: for ( int i = arrayToConvert.length - 1; i > 0; i-- )
You mean i >= 0, I suppose. ;)
that as well
 this is because arr[arr.length] is the elemant after the last
 element.
 
No offense BCS, but for someone so well-spoken and intelligent, I'm kind of shocked at how poor/inconsistent your spelling is. "elemant" and "element" in the same sentence?
Keep (gently) needling me on that. I need to do better. OTOH I have on occasion wondered if I'm borderline dyslexic (My mind just doesn't seem to "see" spelling errors). I've never bothered to get tested so I can't claim it as a reason and even if I did get tested I can't claim it as an excuse*. Really what I need to do is figure out how to get a spell checker plugged into my NG reader :b * there is a fun debate in that fine distinction
Aug 04 2008
prev sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Michael P." <baseball.mjp gmail.com> wrote in message 
news:g77tc7$2fkr$1 digitalmars.com...

 Unfortunately, those didn't work( because of type issues). So I made my 
 own integer one. :)
cast(int)std.math.pow(10, j) ...
 Okay, it's function createArray, which is called by memoryTest. Line 114, 
 115.
 The file is attached.
 Does anyone know I'm getting these array errors?
int[] memoryList; for ( int i = 0; i < lengthOfList; i++ ) { memoryList[i] = rand() % 10; ... Maaaaybe you can see it now. Hint: how long is memoryList?
Aug 04 2008
parent Michael P. <baseball.mjp gmail.com> writes:
Jarrett Billingsley Wrote:

 "Michael P." <baseball.mjp gmail.com> wrote in message 
 news:g77tc7$2fkr$1 digitalmars.com...
 
 Unfortunately, those didn't work( because of type issues). So I made my 
 own integer one. :)
cast(int)std.math.pow(10, j)
 Okay, it's function createArray, which is called by memoryTest. Line 114, 
 115.
 The file is attached.
 Does anyone know I'm getting these array errors?
int[] memoryList; for ( int i = 0; i < lengthOfList; i++ ) { memoryList[i] = rand() % 10; ... Maaaaybe you can see it now. Hint: how long is memoryList?
Oh. I just thought it dynamically allocated memory for each new element. Anyways, I put memoryList.length = lengthOfList above the for statement. Anyways, thanks for the help. :) -Michael P.
Aug 05 2008