Help - Search - Members - Calendar
Full Version: Computing Constant for a loop variable fraction
AC Tools Everything Macro > AC Tool Macros > Macro Development
Musketball
hello, I am writting a macro, and using a compute function to calculate the amount of loops to do based on maxium hitpoints, my problem is when that computation throughs a fraction the macro will not run as you can not cast x spell for 15.4 times, but either 15 or 16, so is there any way to through a condition if compute equals a fraction, add 1, etc, or round up based on .5,etc.

thanks a million.
DaMOB
QUOTE(Musketball @ Aug 17 2009, 02:37 AM) *
hello, I am writting a macro, and using a compute function to calculate the amount of loops to do based on maxium hitpoints, my problem is when that computation throughs a fraction the macro will not run as you can not cast x spell for 15.4 times, but either 15 or 16, so is there any way to through a condition if compute equals a fraction, add 1, etc, or round up based on .5,etc.

thanks a million.

Since loops are only positive we can do
CODE
compute times = floor(X + 0.5)
Loop $times
//code
End
That will do your rounding.
Musketball
QUOTE(DaMOB @ Aug 17 2009, 12:58 AM) *
QUOTE(Musketball @ Aug 17 2009, 02:37 AM) *
hello, I am writting a macro, and using a compute function to calculate the amount of loops to do based on maxium hitpoints, my problem is when that computation throughs a fraction the macro will not run as you can not cast x spell for 15.4 times, but either 15 or 16, so is there any way to through a condition if compute equals a fraction, add 1, etc, or round up based on .5,etc.

thanks a million.

Since loops are only positive we can do
CODE
compute times = floor(X + 0.5)
Loop $times
//code
End
That will do your rounding.



Okay thanks I appreciate it alot. I get the example only the floor thing is that a command or a variable you threw in just for example?
DaMOB
QUOTE(Musketball @ Aug 18 2009, 12:17 PM) *
QUOTE(DaMOB @ Aug 17 2009, 12:58 AM) *
QUOTE(Musketball @ Aug 17 2009, 02:37 AM) *
hello, I am writting a macro, and using a compute function to calculate the amount of loops to do based on maxium hitpoints, my problem is when that computation throughs a fraction the macro will not run as you can not cast x spell for 15.4 times, but either 15 or 16, so is there any way to through a condition if compute equals a fraction, add 1, etc, or round up based on .5,etc.

thanks a million.

Since loops are only positive we can do
CODE
compute times = floor(X + 0.5)
Loop $times
//code
End
That will do your rounding.



Okay thanks I appreciate it alot. I get the example only the floor thing is that a command or a variable you threw in just for example?

That is a command.
Musketball
QUOTE(DaMOB @ Aug 18 2009, 10:27 AM) *
QUOTE(Musketball @ Aug 18 2009, 12:17 PM) *
QUOTE(DaMOB @ Aug 17 2009, 12:58 AM) *
QUOTE(Musketball @ Aug 17 2009, 02:37 AM) *
hello, I am writting a macro, and using a compute function to calculate the amount of loops to do based on maxium hitpoints, my problem is when that computation throughs a fraction the macro will not run as you can not cast x spell for 15.4 times, but either 15 or 16, so is there any way to through a condition if compute equals a fraction, add 1, etc, or round up based on .5,etc.

thanks a million.

Since loops are only positive we can do
CODE
compute times = floor(X + 0.5)
Loop $times
//code
End
That will do your rounding.



Okay thanks I appreciate it alot. I get the example only the floor thing is that a command or a variable you threw in just for example?

That is a command.


Alright, I tried it, but one problem. say the answer from the computation is 7.14, how do I make it say round up to a whole number? or do an if statement?

DaMOB
QUOTE(Musketball @ Aug 18 2009, 09:46 PM) *
QUOTE(DaMOB @ Aug 18 2009, 10:27 AM) *
QUOTE(Musketball @ Aug 18 2009, 12:17 PM) *
QUOTE(DaMOB @ Aug 17 2009, 12:58 AM) *
QUOTE(Musketball @ Aug 17 2009, 02:37 AM) *
hello, I am writting a macro, and using a compute function to calculate the amount of loops to do based on maxium hitpoints, my problem is when that computation throughs a fraction the macro will not run as you can not cast x spell for 15.4 times, but either 15 or 16, so is there any way to through a condition if compute equals a fraction, add 1, etc, or round up based on .5,etc.

thanks a million.

Since loops are only positive we can do
CODE
compute times = floor(X + 0.5)
Loop $times
//code
End
That will do your rounding.



Okay thanks I appreciate it alot. I get the example only the floor thing is that a command or a variable you threw in just for example?

That is a command.


Alright, I tried it, but one problem. say the answer from the computation is 7.14, how do I make it say round up to a whole number? or do an if statement?

rounding up? 7.14, according to math, would be rounded down. I would suggest you use the help function and look up floor (there is a ceil as well) and look at all of the math functions then see what each one does (they work the same as they would in any programming language). Possibly this will help you figure out the ones that you need for your macro.

Good luck.
Musketball
yea, sorry for the confusion. I meant to say if decimal round up or down for whole number, preferably was up since I would want to cast an extra whole spell to heal my target.

I ended up using INT, and will test more later this afternoon.

Thanks guys.
DaMOB
QUOTE(Musketball @ Aug 19 2009, 10:59 AM) *
yea, sorry for the confusion. I meant to say if decimal round up or down for whole number, preferably was up since I would want to cast an extra whole spell to heal my target.

I ended up using INT, and will test more later this afternoon.

Thanks guys.

Int works and is what we used 25 years ago before we had ceil and floor. In today's world int, for this purpose, is frowned upon so it is a bad habit to use.
Musketball
QUOTE(DaMOB @ Aug 19 2009, 09:55 AM) *
QUOTE(Musketball @ Aug 19 2009, 10:59 AM) *
yea, sorry for the confusion. I meant to say if decimal round up or down for whole number, preferably was up since I would want to cast an extra whole spell to heal my target.

I ended up using INT, and will test more later this afternoon.

Thanks guys.

Int works and is what we used 25 years ago before we had ceil and floor. In today's world int, for this purpose, is frowned upon so it is a bad habit to use.


So I will go and look up what ceil and floor do and how to use them together I guess. Anyone give me a helpful example or point me to a resource like a website, since I will not be at the machine with actools installed for while?
DaMOB
QUOTE(Musketball @ Aug 20 2009, 01:50 PM) *
QUOTE(DaMOB @ Aug 19 2009, 09:55 AM) *
QUOTE(Musketball @ Aug 19 2009, 10:59 AM) *
yea, sorry for the confusion. I meant to say if decimal round up or down for whole number, preferably was up since I would want to cast an extra whole spell to heal my target.

I ended up using INT, and will test more later this afternoon.

Thanks guys.

Int works and is what we used 25 years ago before we had ceil and floor. In today's world int, for this purpose, is frowned upon so it is a bad habit to use.


So I will go and look up what ceil and floor do and how to use them together I guess. Anyone give me a helpful example or point me to a resource like a website, since I will not be at the machine with actools installed for while?

Ahem, Google? Ceil and Floor are in every high level language and are all the same.

ceil
<cmath>

double ceil ( double x );

Round up a value.
Returns the smallest integer that is greater or equal to x

Parameters.

x
Floating point value

Return Value.
Ceiling of x.

Example.

/* ceil example */
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
cout << "ceil of 2.3 is " << ceil(2.3) << "\n";
cout << "ceil of 3.8 is " << ceil(3.8) << "\n";
cout << "ceil of -2.3 is " << ceil(-2.3) << "\n";
cout << "ceil of -3.8 is " << ceil(-3.8) << "\n";
return 0;
}

Output:
ceil of 2.3 is 3.0
ceil of 3.8 is 4.0
ceil of -2.3 is -2.0
ceil of -3.8 is -3.0

floor
<cmath>

double floor ( double x );

Round down value.
Returns the largest integer that is less than or equal to x

Parameters.

x
Floating point value

Return Value.
Floor of x.

Example.

/* floor example */
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
cout << "floor of 2.3 is " << floor(2.3) << "\n";
cout << "floor of 3.8 is " << floor(3.8) << "\n";
cout << "floor of -2.3 is " << floor(-2.3) << "\n";
cout << "floor of -3.8 is " << floor(-3.8) << "\n";
return 0;
}

Output:
floor of 2.3 is 2.0
floor of 3.8 is 3.0
floor of -2.3 is -3.0
floor of -3.8 is -4.0
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.