[ 
https://issues.apache.org/jira/browse/YUNIKORN-1403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17727309#comment-17727309
 ] 

Wilfred Spiegelenburg commented on YUNIKORN-1403:
-------------------------------------------------

See this little code example to show the issue: 
https://go.dev/play/p/8TKbbzdh3D5

When you run this on an ARM processor the output is:
{code:java}
inputs:
        9223372036854775807
        1
div in float64: 9223372036854775808.000000
div in int64:   9223372036854775807
absResValue:    -100
div > 0:        true
abs > 0:        false
=================================
inputs:
        9223372036854775807
        -1
div in float64: -9223372036854775808.000000
div in int64:   -9223372036854775808
absResValue:    0
div > 0:        false
abs > 0:        false
=================================
inputs:
        -9223372036854775808
        1
div in float64: -9223372036854775808.000000
div in int64:   -9223372036854775808
absResValue:    0
div > 0:        false
abs > 0:        false
=================================
inputs:
        -9223372036854775808
        -1
div in float64: 9223372036854775808.000000
div in int64:   9223372036854775807
absResValue:    -100
div > 0:        true
abs > 0:        false
=================================
inputs:
        9223372036854775807
        0
div in float64: +Inf
div in int64:   9223372036854775807
absResValue:    -100
div > 0:        true
abs > 0:        false
=================================
inputs:
        -9223372036854775808
        0
div in float64: -Inf
div in int64:   -9223372036854775808
absResValue:    0
div > 0:        false
abs > 0:        false
================================= {code}
And this is the output when run on the playground (Intel processor):
{code:java}
inputs:
        9223372036854775807
        1
div in float64: 9223372036854775808.000000
div in int64:   -9223372036854775808
absResValue:    0
div > 0:        true
abs > 0:        false
=================================
inputs:
        9223372036854775807
        -1
div in float64: -9223372036854775808.000000
div in int64:   -9223372036854775808
absResValue:    0
div > 0:        false
abs > 0:        false
=================================
inputs:
        -9223372036854775808
        1
div in float64: -9223372036854775808.000000
div in int64:   -9223372036854775808
absResValue:    0
div > 0:        false
abs > 0:        false
=================================
inputs:
        -9223372036854775808
        -1
div in float64: 9223372036854775808.000000
div in int64:   -9223372036854775808
absResValue:    0
div > 0:        true
abs > 0:        false
=================================
inputs:
        9223372036854775807
        0
div in float64: +Inf
div in int64:   -9223372036854775808
absResValue:    0
div > 0:        true
abs > 0:        false
=================================
inputs:
        -9223372036854775808
        0
div in float64: -Inf
div in int64:   -9223372036854775808
absResValue:    0
div > 0:        false
abs > 0:        false
================================= 

{code}
Please check the difference between the outputs specially the absResVal. I do 
think that we have a bug in the detection. The check for absResVal for the 
negative case probably should be:
{code:java}
// protect against negative integer overflow
if absResValue >= 0 && div < 0 { {code}

> CalculateAbsUsedCapacity: overflow unit tests
> ---------------------------------------------
>
>                 Key: YUNIKORN-1403
>                 URL: https://issues.apache.org/jira/browse/YUNIKORN-1403
>             Project: Apache YuniKorn
>          Issue Type: Improvement
>          Components: core - common, test - unit
>            Reporter: Wilfred Spiegelenburg
>            Assignee: Ting Yao,Huang
>            Priority: Major
>              Labels: newbie, pull-request-available
>
> CalculateAbsUsedCapacity is guarded against positive and negative overflow. 
> The postive case is unit tested. The negative case is not unit tested.
> Need to add a test case for te negative side:
> {code}
> // protect against negative integer overflow
> if absResValue > 0 && div < 0 {
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to