This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-10-21 09:51:58

TCoZ
Scratcher
Registered: 2007-10-21
Posts: 2

I need some help...

For a certain program I wish to create, I need a floor function. Floor takes the number and cuts off the decimal, unlike rounding. Rouding can raise the number.

So...
floor(3.7) == 3
<round(3.7)> == 4
floor(3.252) == 3
<round(3.252)> = 3

So yeah. How would I recreate the floor function?

Offline

 

#2 2007-10-21 11:08:17

bigB
Scratcher
Registered: 2007-06-09
Posts: 100+

Re: I need some help...

try using the abs function
goodluck


http://scratch.mit.edu/projects/bigB/260981 Draw to Text
http://scratch.mit.edu/projects/bigB/181829 3D Stunt Flyer

Offline

 

#3 2007-10-21 11:36:41

TCoZ
Scratcher
Registered: 2007-10-21
Posts: 2

Re: I need some help...

The abs function does something different.

Anyway, I found a soloution...
< set{floorx}to(< round(x) >) >
< if>< (  floorx < > > x  ) >
< change{floorx}by(-1) >
< end>

Last edited by TCoZ (2007-10-21 11:38:12)

Offline

 

#4 2007-10-21 11:59:28

ElMikkino
Scratcher
Registered: 2007-09-19
Posts: 76

Re: I need some help...

GAH!!! Complicated Maths!!!!!!  wink


Certified Bunnay Agent
--------ElMikkino-----------

Offline

 

#5 2007-10-21 13:36:16

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: I need some help...

ElMikkino wrote:

GAH!!! Complicated Maths!!!!!!  wink

Not really, he is just trying to replicate a Math method that are part of most programming languages. Here is a list of math methods.

Math.PI   calls the number that is the circumference of a circle (That number is 3.14159265) that is known as PI

Math.ceil   rounds a number up

Math.floor  rounds a number down

Math.round  rounds a number up if it's decimal value is greater or equal to 0.5 otherwise it's rounded down

Math.abs   if a number is negative this math method will make it positive 

Math.sqrt  finds the square root of a number

Math.pow(x,y)  x is raised by the power of y

Math.max finds the maximum of 2 numbers

Math.min finds the minimum of 2 numbers

Math.random generates a random number from 0 to 0.9999....

//Trigonometry math functions
Math.sin  Calls the sin function

Math.cos  calls the cosine function

Math.tan calls the tangent function


There are also a few more math functions that exist.

Last edited by archmage (2007-10-21 13:37:24)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#6 2007-10-21 17:52:42

ElMikkino
Scratcher
Registered: 2007-09-19
Posts: 76

Re: I need some help...

Math.abs, Math.sqrt, Math.pow, Math.tan and Math.sin sound wrong....

Last edited by ElMikkino (2007-10-21 17:53:21)


Certified Bunnay Agent
--------ElMikkino-----------

Offline

 

#7 2007-10-21 18:06:48

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: I need some help...

ElMikkino wrote:

Math.abs, Math.sqrt, Math.pow, Math.tan and Math.sin sound wrong....

How do they sound wrong? I don't see what you mean.


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#8 2007-10-21 19:57:50

ElMikkino
Scratcher
Registered: 2007-09-19
Posts: 76

Re: I need some help...

When you say them out loud, they do. Like, what if math had abs?! Or math got a tan?! Or math squirted stuff?!

Last edited by ElMikkino (2007-10-21 19:58:43)


Certified Bunnay Agent
--------ElMikkino-----------

Offline

 

#9 2007-10-21 21:50:06

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: I need some help...

ElMikkino wrote:

When you say them out loud, they do. Like, what if math had abs?! Or math got a tan?! Or math squirted stuff?!

Yea, programming languages like to use shorter words instead of saying the entire word like absolute or tangent or square root.

To print in a line of text in java you would say println instead of printline


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

Board footer