absolute-value

Absolute value for floats in core OCaml

I am in need of an absolute value function for floats in OCaml and the core language doesn't seem to possess one, so I wrote the following: let absF (f:float) = if f > 0.0 then f else (f *. -1.0);; which seems to work for positives but not for negatives, citing: This expression has type float -> float but is here used with type int ...

How do you programatically position an object in Silverlight?

In Flash this question is answered really easy because you can set the X and Y coordinates of an object: newxpos = object._x; newypos = object._y; How do you do the same in Silverlight? ...

Unsigned int to signed in php

I got a problem with ip2long in PHP5. It appears, that in 32bit OS ip2long returns signed int, and in 64bit OS unsigned int is returned. My application is working on 10 servers, and some are 32bit and some are 64bit, so I need all them to work same way. In PHP documentation there is a trick to make that result always unsigned, but since ...

How can I find the difference between 2 values in C#?

I am working with an Oscillator that fluctuates between 10.000000 and -10.000000 The value changes say every 5 minutes. I want to find the difference between the current value and the value of 5 minutes ago. Here is my logic. 1 bar ago (1BA)= -.2 Current bar (CB) = .3 Wouldn't I get a value of 1 if I did something like: Abs(CB) - A...

Absolute value in vb.net

How do you get the absolute value of a number in vb.net? Is there a function built in? I know I can simply code a function myself, but I want to know if there is one already there first. It seems so simple, I could probably make it in three lines, so I would be surprised if there isnt one.... Thanks! ...

isn't there an operator in c to change the sign of a int float etc from negative to positive or vice versa?

trying to find absolute value and i thought there was a simple way to just invert the sign with '~' or something. ...

Is there any reason this isn't redundant code?

I came across this code in some existing codebase: double rad = ComputeCurviness(); double off = Math.Abs(rad); if (rad < 0) off = -off; It seems to be basically just making off equal to rad. The variables are used interchangeably later in the code. Is there any reason to leave this code in? ...

How to convert a negative number to positive?

How can I convert a negative number to positive in Python? (And keep that positive value.) ...