Skip to content

[Closed]abs function return negative number #9571

Closed
@yikescloud

Description

@yikescloud

//current_time and check_time both are uint32_t, and current_time always large than check_time
Some of my core codeline

current_time = millis();
int v_beats;
v_beats = abs((current_time - check_start)/20 - 40);
Serial.println(v_beats);

Serial port will return negtive number.
But if I change it to
int v_beats;
v_beats = (current_time - check_start)/20 - 40;
v_beats = abs(v_beats);
Serial.println(v_beats);

The result will be OK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: InvalidOff topic for this repository, or a bug report determined to not actually represent a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions