Go Back   Cockos Incorporated Forums > REAPER Forums > REAPER Bug Reports

Reply
 
Thread Tools Display Modes
Old 09-26-2017, 03:06 AM   #1
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default GetMediaItemInfo_Value API does not return the real values



and the test code:
Code:
item = reaper.GetSelectedMediaItem(0,1)
previousitem = reaper.GetSelectedMediaItem(0,0)
secondstart = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
firstend = reaper.GetMediaItemInfo_Value(previousitem, "D_POSITION") + reaper.GetMediaItemInfo_Value(previousitem, "D_LENGTH")
reaper.ShowConsoleMsg("end of first item is "..firstend.."\n")
reaper.ShowConsoleMsg("start of second item is "..secondstart.."\n")
if firstend == secondstart then
  reaper.ShowConsoleMsg("They are equal")
else
  reaper.ShowConsoleMsg("They are not equal")
end
Either, LUA doesn't do its math well, or the Reaper API does not return the real values.

Reaper v5.40 x86 , Windows 7 x64
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 09-27-2017 at 06:25 AM.
amagalma is offline   Reply With Quote
Old 09-27-2017, 07:01 AM   #2
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

ShowConsoleMsg (and the IDE) rounds the numbers to 11 decimals.

Under the hood, however, REAPER's actual time values have something like 15 decimals.

AFAIK, the last decimals are not entirely reliable, and stuff that are supposed to be on exactly the same grid position can sometimes differ by a few quadrillionths of the second.

Last edited by juliansader; 09-27-2017 at 07:38 AM.
juliansader is offline   Reply With Quote
Old 09-27-2017, 07:16 AM   #3
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

This is confusing.. So, how can one know what are the real values since both the console and the IDE round them? And how one can do maths, if the maths you do are applied to different values and not to the ones you thought?...
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 09-27-2017, 07:25 AM   #4
schwa
Administrator
 
schwa's Avatar
 
Join Date: Mar 2007
Location: NY
Posts: 15,821
Default

Code:
reaper.ShowConsoleMsg(string.format("%.16f",firstend))
reaper.ShowConsoleMsg(string.format("%.16f",secondstart))

should show that the numbers are different (probably because the start of the second is snapped to sample).
schwa is offline   Reply With Quote
Old 09-27-2017, 07:31 AM   #5
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by amagalma View Post
how one can do maths, if the maths you do are applied to different values and not to the ones you thought?...
For starters, don't equality compare floating point numbers :
Code:
if firstend == secondstart
It's a pretty rare occasion when you can truly expect 2 floats to be equal if they come from some source that is not entirely under your control.

You can compare their absolute difference to some value though :
Code:
local a = 0.000000001
local b = 0.000000001007
if math.abs(a-b)<0.00000000001 then print("approx equal") 
else print("not equal") end
It is left up to you to decide what is that acceptable difference...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 09-27-2017, 09:54 AM   #6
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

Thanks to all of you for the answers! So, it appears it's not a bug, but a whimsy when doing maths with floating numbers. I get it! Thanks to all of you for the lesson!
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma 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:34 PM.


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