Skip to content

[Go Migration] Fix screws_tilt_adjust.test floating-point rounding #2

@AndySze

Description

@AndySze

Problem

Step interval/count values differ due to floating-point rounding:

Expected: interval=8610 count=7 add=-74
Actual:   interval=8625 count=6 add=-74

Large single-step movements show dramatic differences:

Expected: interval=4192000 count=1 add=0
Actual:   interval=192000 count=1 add=0  (22x difference!)

Root Cause

Go (runtime.go:577-582):

return uint64(int64(printTime * th.mcuFreq))  // int64 intermediate

Python (clocksync.py:123-124):

return int(print_time * self.mcu_freq)  // Direct truncation

The int64 intermediate conversion in Go causes different rounding behavior.

Proposed Fix

File: go/pkg/hosth4/runtime.go line 577-582

func (th *toolhead) printTimeToClock(printTime float64) uint64 {
    if printTime <= 0.0 {
        return 0
    }
    return uint64(printTime * th.mcuFreq)  // Direct conversion, no int64
}

Verification

./scripts/go_migration_golden.py compare --only screws_tilt_adjust --mode strict

Estimate

~1 hour (simple one-line fix)

Parent Issue

Part of #1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions