wtf now? division is always rounded?

About advanced scenes, and the Thyme scripting language used in Algodoo.

wtf now? division is always rounded?

Postby pixartist » Wed Jan 20, 2010 2:16 pm

got this code:
Code: Select all
(e)=>{
    Scene.my.timer = Scene.my.timer + 1;     scene.my.current_0 = scene.my.robotMoves_0((scene.my.step_0 * 2) + 2);     scene.my.next_0 = scene.my.robotMoves_0((scene.my.step_0 + 1) * 2 + 2);     scene.my.current_0_t = scene.my.robotMoves_0((scene.my.step_0 * 2) + 1);     scene.my.next_0_t = scene.my.robotMoves_0((scene.my.step_0 + 1) * 2 + 1);     Scene.my.step_0 < (Scene.my.robotMoves_0(0) - 1) ? {         Scene.my.phase = ((scene.my.timer - scene.my.current_0_t) / (scene.my.next_0_t - scene.my.current_0_t));         Scene.my.angle_0_target = ((1.0 - (Scene.my.phase * scene.my.current_0)) + (Scene.my.phase * scene.my.next_0)) * ( - math.pi);         Scene.my.timer > scene.my.robotMoves_0(((scene.my.step_0 + 1) * 2) + 1) ? {Scene.my.step_0 = Scene.my.step_0 + 1} : {}     } : {} }

ok look at the phase variable...

now have a look at the attached pic:

so (149-120)/(200-120) = 0.0 ?????

there are no error message, i checked divisor and dividend, both are okay.. so WHAT THE HECK ?

edit: when divisor = divident, it's 1 ..
Attachments
algobug.jpg
(87.28 KiB) Not downloaded yet
Image
pixartist
 
Posts: 65
Joined: Wed Sep 02, 2009 5:30 pm

Re: wtf now? division is always rounded?

Postby KarateBrot » Wed Jan 20, 2010 3:06 pm

You're dividing integer values. It sounds crazy but your solution was calculated correctly because your solution will also be an integer value.
If you want algodoo to let it calculate decimal places you first have to make the fraction a float value.
It's easy: just put ".0" at the end of one value. The thyme function for that is math.tofloat()


For example:
Code: Select all
(149.0-120)/(200-120) = 0.3625
Last edited by KarateBrot on Wed Jan 20, 2010 3:22 pm, edited 1 time in total.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: wtf now? division is always rounded?

Postby Kilinich » Wed Jan 20, 2010 3:21 pm

not a bug.

1 is integer: 1 * 2.2 = 2
1.0 is float: 1.0 * 2.2 = 2.2
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: wtf now? division is always rounded?

Postby KarateBrot » Wed Jan 20, 2010 3:23 pm

Kilinich wrote:not a bug.

1 is integer: 1 * 2.2 = 2
1.0 is float: 1.0 * 2.2 = 2.2


But the solution for 1*2.2 will also be 2.2. There just needs to be one float value and the solution will get converted to float.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests