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

Reply
 
Thread Tools Display Modes
Old 07-08-2020, 02:23 PM   #1
mrelwood
Human being with feelings
 
mrelwood's Avatar
 
Join Date: Nov 2006
Location: Finland
Posts: 1,528
Default JSFX: Rounding discrepancy between MacOS and Windows

Some parameter values are shown incorrectly when drawing them on display on a JSFX plugin on REAPER for MacOS.

For example:
Code:
value = 0.03;
gfx_drawstr( sprintf(#value,"%g", value ) );
Shows on display as "0.0299999".

Screenshot attached, as well as a small JS plugin to demonstrate the issue. It will probably not show any issues on Windows, but on MacOS as you drag the slider that moves in 0.01 increments, some values are drawn just short of the actual value.
Attached Images
File Type: png REAPER JS Rounding Error.png (44.2 KB, 295 views)
Attached Files
File Type: txt _BUG_RoundingError.txt (308 Bytes, 294 views)
__________________
______Announcing__mrelwood plugins______
.. MacBook Pro 16" Late '19 .. Scarlett 6i6, Saffire Pro 24 DSP (+ADA8000) .. FCA610 .. EVE SC207 .. Focal: Shape 65, Alpha 65, CMS 40, Listen Pro ..
mrelwood is offline   Reply With Quote
Old 07-13-2020, 11:45 AM   #2
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,721
Default

Ah yeah, the FPU rounding state... Let me fix that.
Justin is offline   Reply With Quote
Old 07-14-2020, 12:37 AM   #3
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

I'm not really sure, but I don't think that's FPU rounding, but rather the difference in printf() implementation between MSVC and GCC/Clang.
Tale is offline   Reply With Quote
Old 07-14-2020, 03:27 PM   #4
Justin
Administrator
 
Justin's Avatar
 
Join Date: Jan 2005
Location: NYC
Posts: 15,721
Default

Quote:
Originally Posted by Tale View Post
I'm not really sure, but I don't think that's FPU rounding, but rather the difference in printf() implementation between MSVC and GCC/Clang.
For the case of printf("%g",.3), it appears to be -- the MSVC version doesn't depend on the FP rounding flag, whereas the macOS/linux versions do (restoring the FP rounding state to nearest before calling snprintf() makes macOS output 0.3, at least). This should be fixed in +dev0713...

I'm imagining there's some script out there that uses sprintf() to figure out what OS it is running on, oops.
Justin is offline   Reply With Quote
Old 07-14-2020, 10:20 PM   #5
mrelwood
Human being with feelings
 
mrelwood's Avatar
 
Join Date: Nov 2006
Location: Finland
Posts: 1,528
Default

Quote:
Originally Posted by Justin View Post
For the case of printf("%g",.3), it appears to be -- the MSVC version doesn't depend on the FP rounding flag
The issue is actually not limited to the %g flag, as printing with printf("%.2f",.3) prints "0.29" (on MacOS at least, not sure about Windows).


Ps. Nice to see you grab on with the issue! I should've reported this two years ago when I first noticed it... XoD
__________________
______Announcing__mrelwood plugins______
.. MacBook Pro 16" Late '19 .. Scarlett 6i6, Saffire Pro 24 DSP (+ADA8000) .. FCA610 .. EVE SC207 .. Focal: Shape 65, Alpha 65, CMS 40, Listen Pro ..
mrelwood is offline   Reply With Quote
Old 07-15-2020, 12:11 AM   #6
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Quote:
Originally Posted by Justin View Post
For the case of printf("%g",.3), it appears to be -- the MSVC version doesn't depend on the FP rounding flag, whereas the macOS/linux versions do (restoring the FP rounding state to nearest before calling snprintf() makes macOS output 0.3, at least). This should be fixed in +dev0713...
Fix confirmed, and for e.g. printf("%.1f", 0.49) as well (before: 0.4; now: 0.5). And thanks for the info!

Quote:
Originally Posted by Justin View Post
I'm imagining there's some script out there that uses sprintf() to figure out what OS it is running on, oops.
Yeah, maybe... However, I would rather have consistent printf(), YMMV. Also, you could always add another method/system variable to detect the OS, should this be an actual issue for anyone.
Tale is offline   Reply With Quote
Old 07-15-2020, 12:16 AM   #7
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

FYI: I already thought this was discussed this before, and apparently it was, including OS detect:

https://forum.cockos.com/showthread.php?t=168401
Tale 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 06:30 AM.


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