# Little confuse about decay function source code

**URL:** <https://discuss.elastic.co/t/little-confuse-about-decay-function-source-code/336296>\
**Category:** Elasticsearch\
**Created:** [June 18, 2023, 5:17am UTC](https://discuss.elastic.co/t/little-confuse-about-decay-function-source-code/336296 "2023-06-18T05:17:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RandalTeng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/randalteng/32/122399_2.png) [@RandalTeng](https://discuss.elastic.co/u/RandalTeng)\
**Post date:** [June 18, 2023, 5:17am UTC](https://discuss.elastic.co/t/little-confuse-about-decay-function-source-code/336296/1 "2023-06-18T05:17:50Z")

</div>

hi guys, I recently read some source code about the decay function.  
there is some code doc, I can't figure out why it should be.

the code line is:  
`https://github.com/elastic/elasticsearch/blob/13fb93511c23fe0d1a02de07644a0415253010c5/server/src/main/java/org/elasticsearch/script/ScoreScriptUtils.java#L236`

doc:  
`// as java.lang.Math#abs(long) is a forbidden API, have to use this comparison instead`

why this doc said, the `Math.abs` is a forbidden API? As far as I know, this API is ok for calling.

anyone who can give me a hit above is generous.

thanks a lot.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [June 18, 2023, 6:38am UTC](https://discuss.elastic.co/t/little-confuse-about-decay-function-source-code/336296/2 "2023-06-18T06:38:27Z")

</div>

It's easy to assume that `Math.abs` only returns non-negative results, but  
`Math.abs(Integer.MIN_VALUE)` is `Integer.MIN_VALUE` which is negative. This has caused bugs in the past so it's best to avoid it.

---

<div class="post-metadata">

**Author:** ![RandalTeng](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/randalteng/32/122399_2.png) [@RandalTeng](https://discuss.elastic.co/u/RandalTeng)\
**Post date:** [June 18, 2023, 8:36am UTC](https://discuss.elastic.co/t/little-confuse-about-decay-function-source-code/336296/3 "2023-06-18T08:36:15Z")

</div>

thanks for your reply, had a try about `Math.abs(Integer.MIN_VALUE)` after your hit.  
this feature I didn't know before.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 16, 2023, 8:37am UTC](https://discuss.elastic.co/t/little-confuse-about-decay-function-source-code/336296/4 "2023-07-16T08:37:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
