The Abs
function in the Go programming language is used to find the absolute value of any given number.
Given a positive number, it is returned unchanged, while if a negative number is given as input to the
Abs
function, the number’s positive equivalent is returned.
To use this function, you must import the math
package in your file and access the Abs
function within it using the .
notation [math.Abs
]. Here, Abs
is the actual function, while math
is the Go package that stores the definition of this function.
Function definition
The definition of the Abs
function inside the math
package is:
Parameters
The Abs
function takes a single argument of type float64 and is the number you want to find the absolute value of.
Return value
The Abs
function returns a single value of type float64. This value represents the absolute value of the given argument. So, all returned values are greater or equal to 0.
The above statement has the following two types of arguments that are given to it:
Infinity: Upon sending either positive or negative infinity as an argument to the
Abs
function, it returns positive infinity.NAN: Upon sending a non-numeric argument the
Abs
function returns NAN.
Examples
The following is a simple example in which we find out the value of 25:
package main import ["fmt" "math"] func main[] { x := -25.0 y := math.Abs[x] fmt.Print[y] }
Although passing an integer variable as an argument to the Abs
function results in an error, if you directly pass an integer
value to it, the value gets automatically typecasted into a float64, and the function works as intended, as displayed by the following example:
package main import ["fmt" "math"] func main[] { y := math.Abs[math.Inf[1]] fmt.Print[y] }
Copyright ©2022 Educative, Inc. All rights reserved
mjt at jpeto dot net ¶
13 years ago
I strongly recommend, that you use
header[$_SERVER["SERVER_PROTOCOL"]." 404 Not Found"];
instead of
header["HTTP/1.1 404 Not Found"];
I had big troubles with an Apache/2.0.59 [Unix] answering in HTTP/1.0 while I [accidentially] added a "HTTP/1.1 200 Ok" - Header.
Most of the pages were displayed correct, but on some of them apache added weird content to it:
A 4-digits HexCode on top of the page [before any output of my php script], seems to be some kind of checksum, because it changes from page to page and browser to browser. [same code for same page and browser]
"0" at the bottom of the page [after the complete output of my php script]
It took me quite a while to find out about the wrong protocol in the HTTP-header.
Marcel G ¶
12 years ago
Several times this one is asked on the net but an answer could not be found in the docs on php.net ...
If you want to redirect an user and tell him he will be redirected, e. g. "You will be redirected in about 5 secs. If not, click here." you cannot use header[ 'Location: ...' ] as you can't sent any output before the headers are sent.
So, either you have to use the HTML meta refresh thingy or you use the following:
Hth someone
Dylan at WeDefy dot com ¶
14 years ago
A quick way to make redirects permanent or temporary is to make use of the $http_response_code parameter in header[].
The HTTP status code changes the way browsers and robots handle redirects, so if you are using header[Location:] it's a good
idea to set the status code at the same time. Browsers typically re-request a 307 page every time, cache a 302 page for the session, and cache a 301 page for longer, or even indefinitely. Search engines typically transfer "page rank" to the new location for 301 redirects, but not for 302, 303 or 307. If the status code is not specified, header['Location:'] defaults to 302.
mandor at mandor dot net ¶
16 years ago
When using PHP to output an image, it won't be cached by the client so if you don't want them to download the image each time they reload the page, you will need to emulate part of the HTTP protocol.
Here's how: