fast integer based trigonometry for chdk and lua - page 2 - General Discussion and Assistance - CHDK Forum

fast integer based trigonometry for chdk and lua

• 17 Replies
• 9173 Views

rudi

• 129
• A590IS_101B, SX260HS_100B
Re: fast integer based trigonometry for chdk and lua
« Reply #10 on: 27 / March / 2013, 07:46:59 »
Yes, I think so. Anything else?

waterwingz

• 12132
Re: fast integer based trigonometry for chdk and lua
« Reply #11 on: 27 / March / 2013, 08:26:34 »
Yes, I think so. Anything else?
Well,  I guess the obvious ones would be  imath.ceil(a)imath.round(a) & imath.random(min,max) ?
« Last Edit: 27 / March / 2013, 09:25:38 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

rudi

• 129
• A590IS_101B, SX260HS_100B
Re: fast integer based trigonometry for chdk and lua
« Reply #12 on: 28 / March / 2013, 02:18:14 »
imath.random(min,max)
I would use math.random(). What is your suggest feature?
Code: [Select]
math.random(0, imath.scale)  -- 0 to 1'000
math.random(imath.scale, 5*imath.scale)  -- 1'000 to 5'000

waterwingz

• 12132
Re: fast integer based trigonometry for chdk and lua
« Reply #13 on: 28 / March / 2013, 08:04:18 »
imath.random(min,max)
I would use math.random(). What is your suggest feature?
Code: [Select]
math.random(0, imath.scale)  -- 0 to 1'000
math.random(imath.scale, 5*imath.scale)  -- 1'000 to 5'000

I agree that this is the least useful addition of the four I suggested.   Its really just :

Code: [Select]
function imath.random(min,max)
return( math.random(min,max)
end
I suggested it more for coding style consistency - much like using imath.scale instead of 1000.

Ported :   A1200    SD940   G10    Powershot N    G16

rudi

• 129
• A590IS_101B, SX260HS_100B
Re: fast integer based trigonometry for chdk and lua
« Reply #14 on: 28 / March / 2013, 12:21:56 »
I don't know how to implement random in imath library for using imath.random() in script and hostlua.
Attached is the patch for this new imath functions:
Code: [Select]
int(5010) = 5000 / int(-5010) = -5000
frac(5010) = 10 / frac(-5010) = -10
ceil(5010) = 6000 / ceil(-5010) = -5000
floor(5010) = 5000 / floor(-5010) = -6000
round(5010) = 5000 / round(-5010) = -5000

waterwingz

• 12132
Re: fast integer based trigonometry for chdk and lua
« Reply #15 on: 28 / March / 2013, 21:59:29 »
Works fine for me too.  Ignore my suggestion for an imath.random function.

Are you going to update the svn with this?
Ported :   A1200    SD940   G10    Powershot N    G16

rudi

• 129
• A590IS_101B, SX260HS_100B
Re: fast integer based trigonometry for chdk and lua
« Reply #16 on: 30 / March / 2013, 04:25:14 »
Are you going to update the svn with this?
Not now, I don't have development environment with me. But you can do that if you want.

rudi

• 129
• A590IS_101B, SX260HS_100B
Re: fast integer based trigonometry for chdk and lua
« Reply #17 on: 05 / April / 2013, 06:22:16 »
I detect some bugs in imath library.

At first for example in function imath.ceil(). Here is using wrong transformation with rounding INT2FIXEDR(); INT2FIXEDR(5'000) should be 5.0005 -> ceil(5.0005) = 6.0000. But the result is correct 5.000. There is a bug in round-in part (round-out is also incorrect). I replaced all INT2FIXEDR() with INT2FIXED() for equal input values to previous implementation.

At second imath.frac() is now calculated immediately in imath library. The FIXED fraction part is not in any case equal to INT fraction part. For example INT2FIXED(5'010) = 5.00999 and not 5.01000.

Attachment include updated script imath.lua with new functions from Changeset 2655.