|
|
|
07-14-2019, 09:48 PM
|
#1
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Question about item's length and source length
Here is a simple reaper project that has only an item. I already set it to media source start and end. So the item's length and source length of it are suppose to be equal, right?
But I ran this script to check:
Code:
it=reaper.GetMediaItem(0, 0)
tk=reaper.GetActiveTake(it)
length=reaper.GetMediaItemInfo_Value(it, "D_LENGTH")
source=reaper.GetMediaItemTake_Source(tk)
orilen=reaper.GetMediaSourceLength(source)
msg("length="..length)
msg("orilen="..orilen)
msg("length-orilen="..length-orilen)
and I got this result:
Code:
length=3.5526530612245
orilen=3.5526530612245
length-orilen=4.4408920985006e-016
So why doesn't length-orilen equal to zero, but a number that is clse to zero?
Last edited by dsyrock; 04-14-2020 at 08:26 PM.
|
|
|
07-15-2019, 04:40 AM
|
#2
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,902
|
Seems there is some roubding issue, maybe from a sample or sub sample value. Not sure why.
|
|
|
07-19-2019, 02:52 AM
|
#3
|
Human being with feelings
Join Date: Jul 2009
Posts: 3,714
|
Check out this thread: GetMediaItemInfo_Value API does not return the real values.
* REAPER's IDE and ShowConsoleMsg don't display floating point numbers to their full precision, so numbers may seem equal even if they are not.
* 4.4408920985006e-016 is close to the limits of the previous two numbers' 64-bit float precision, so this is probably just normal floating point errors, not sample rounding.
* Floating point numbers should never be compared directly for equality. Instead, compare their difference to a tiny cutoff value such as 1e-14 (or whatever is about 14 decimals smaller than your expected value range).
Last edited by juliansader; 07-19-2019 at 03:30 AM.
|
|
|
09-10-2021, 05:15 AM
|
#4
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,067
|
Could it be, that this issue happens, because the take properties (in ticks) get converted to project time and therefore have a different precision?
|
|
|
09-10-2021, 07:13 AM
|
#5
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 15,823
|
4e-16 is less than one-billionth of a sample at 48k
|
|
|
09-10-2021, 10:32 AM
|
#6
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,902
|
@schwa
This can be enough to break some equality check :P
|
|
|
11-03-2022, 09:59 AM
|
#7
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,067
|
I found another solution for this and wanted to share it.
I'm using the following round function in order to round both values, 5 digits after the comma:
Code:
local function Round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
Thanks to LBX for the function!
|
|
|
11-04-2022, 04:31 AM
|
#8
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,067
|
Okay, strike that, it works with some values, but not all.
|
|
|
11-04-2022, 04:55 AM
|
#9
|
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,630
|
The craziest thing I once did was to convert these values to string and round them character by character. Then convert back into number.
I didn't know anything about float-precision at that time o_O
|
|
|
11-04-2022, 04:55 AM
|
#10
|
Human being with feelings
Join Date: Oct 2017
Location: Black Forest
Posts: 5,067
|
Been there, done that, got the T-Shirt...
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 04:56 PM.
|