Amber icon indicating copy to clipboard operation
Amber copied to clipboard

[BUG] Concate value on print generate wrong bash

Open Mte90 opened this issue 1 year ago • 4 comments

An example code:

pub fun round(number: Num): Num {
    let operator = "+"
    if number > 0 {
        operator = "-"
    }

    return unsafe $echo "({number}{operator}0.5)/1" | bc$ as Num
}

Generates:

round__1_v0() {
    local number=$1
    local operator="+"
    if [ $(echo ${number} '>' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
        operator="-"
    fi
    __AMBER_VAL_0=$(echo "(${number}0.5)/1" | bc${operator})
    __AS=$?
    __AF_round1_v0="${__AMBER_VAL_0}"
    return 0
}

Mte90 avatar Aug 30 '24 10:08 Mte90

so.. what's the problem?

b1ek avatar Aug 30 '24 16:08 b1ek

The line:

    __AMBER_VAL_0=$(echo "(${number}0.5)/1" | bc${operator})

Is wrong.

It should be:

    __AMBER_VAL_0=$(echo "(${number}${operator}0.5)/1" | bc)

Mte90 avatar Aug 30 '24 16:08 Mte90

huh.. that is like super weird

b1ek avatar Aug 31 '24 07:08 b1ek

I think I know what's the problem and how to fix it. But I have to test it first on my machine

Ph0enixKM avatar Sep 02 '24 10:09 Ph0enixKM

New amber code:

pub fun round(number: Num): Num {
    let operator = "+"
    if number > 0 {
        operator = "-"
    }

    return trust $echo "({number}{operator}0.5)/1" | bc$ as Num
}
round(1.5)

The issue is still there

Mte90 avatar Jul 15 '25 09:07 Mte90