Old 07-14-2019, 09:48 PM   #1
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 150
Default 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?
Attached Files
File Type: zip test.zip (338.9 KB, 4 views)
dsyrock is offline   Reply With Quote
Old 07-15-2019, 04:40 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 5,919
Default

Seems there is some roubding issue, maybe from a sample or sub sample value. Not sure why.
X-Raym is offline   Reply With Quote
Old 07-19-2019, 02:52 AM   #3
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 2,659
Default

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.
juliansader is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 08:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.