Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why I am getting negative result for negativeValue.abs()?

I have an extension like;

extension x on num{}

and this extension contains below function;

double get wP {
assert(this >= 0.0, "value.wP: value can't be lower than 0.0!");
assert(this <= 1.0, "value.wP: value can't be bigger than 1.0!");
return (this.abs() * SizeService.instance.width).abs();}

SizeService.instance.width is a integer and it is = 50.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So, why -1.0.wp returning -50 ?

and I wan’t to block all negative variable like;
-0.0 too but if I write assert like

assert(!this.isNegative, "Error bla bla");

it is not catching the negative value 🙁

so my question is here;

how can I block all negative and nan variables or if I can’t do it, how can I convert all negative variables to positive ones ?

-0.0 is too.

because this.abs() is not working :/

thank u very much for any helpful answer!

>Solution :

-1.0.wP is in fact the same as -(1.0.wP)

Instead, try with (-1.0).wP

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading