Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
August 04, 2008 exponent operator/library function | ||||
---|---|---|---|---|
| ||||
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. |
August 04, 2008 Re: exponent operator/library function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael P. | 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);
|
August 04, 2008 Re: exponent operator/library function | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS Attachments: | 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.
|
August 04, 2008 Re: exponent operator/library function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael P. | 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.
|
August 04, 2008 Re: exponent operator/library function | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | "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? |
August 04, 2008 Re: exponent operator/library function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michael P. | "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? |
August 04, 2008 Re: exponent operator/library function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 |
August 05, 2008 Re: exponent operator/library function | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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.
|
Copyright © 1999-2021 by the D Language Foundation