Fix #128102: Integer Math division has only float precision #128123
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#128123
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "CharlieJolly/blender:fix128102"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The additional division modes were implemented with float
division then rounding to match float > int conversion in
existing float to int node.
As pointed out in the bug report the precision here is limited.
This patch replaces the float division with integer math which
increases the precision to much higher numbers.
Divide Round by due to the way it is calculated has less precision
than Divide Floor and Divide Ceil.
@ -117,3 +117,3 @@
"Multiply", [](int a, int b) { return a * b; }, exec_preset);
static auto divide_fn = mf::build::SI2_SO<int, int, int>(
"Divide", [](int a, int b) { return math::safe_divide(a, b); }, exec_preset);
"Divide", [](int a, int b) { return (b != 0) ? a / b : 0; }, exec_preset);
Isn't this the same as the
math::safe_divide
?My mistake, I copied the function in full for testing.
@ -130,1 +130,3 @@
[](int a, int b) { return int(math::round(math::safe_divide(float(a), float(b)))); },
[](int a, int b) {
const int c = abs(b);
return (a >= 0) ? math::safe_divide((2 * a + c), (2 * c)) * math::sign(b) :
Would be good to extract that into a separate function in blenlib and to add some unit tests for it. (e.g. in
BLI_math_base_safe_test.cc
)Where does this formular come from? Shouldn't it be possible to round based on the remainder?
This was derived from
divide_round_i
but fixed to be safe and handle negative inputs to match float output frommath::round(math::safe_divide(a, b))
.I've added a comment to this affect and pulled into a separate function.
I think it is easier to keep here rather than bloat blenlib but if you want it in blenlib can you advise which file it should go?
ok, fine with me, it would just be nice to have some kinds of test here, a regression test can be ok as well though.
@blender-bot build
Test file showing precision fixes from this patch