Amber
Amber copied to clipboard
[BUG] Concate value on print generate wrong bash
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
}
so.. what's the problem?
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)
huh.. that is like super weird
I think I know what's the problem and how to fix it. But I have to test it first on my machine
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