Skip to content

erroneous output for abs( ) #5

@mogando668

Description

@mogando668

all of these are positive values, but frequently abs() erroneously negate them, cuz the function was performing a string compare, in which leading-edge spaces ( " " ) , tabs ( \t ), "+", or "-", all rank lower in byte-ordinance value compared to "0"

	# gawk profile, created Sun Jun  5 06:08:41 2022

	# BEGIN rule(s)

	BEGIN {
     1  	print abs("+0.000000000000000000001"), abs(" 0.000000000000000000001")
     1  	print abs(".5"), abs(.5)
     1  	print abs("+5"), abs(+5)
     1  	print abs(sprintf("%+.20f", exp(1))), abs("+" exp(1)), abs(exp(1))
	}


	# Functions, listed alphabetically

     9  function abs(v)
	{
     9  	if (v < 0) { # 6
     6  		return -v
     3  	} else {
     3  		return v
		}
	}
——————————
-1e-21 -1e-21
-0.5 .5
-5 +5
-2.71828 -2.71828 2.71828

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