Open In App

Perl | cos() Function

Last Updated : 25 Jun, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

This function is used to calculate cosine of a VALUE or $_ if VALUE is omitted. The VALUE should be expressed in radians.

Syntax: cos(VALUE)

Parameters:
VALUE in the form of radians

Returns: Function returns cosine of VALUE.

Example 1:




#!/usr/bin/perl
  
# Calling cos function
$var = cos(5);
  
# Printing value of cos(5)
print "cos value of 5 is $var";


Output:

cos value of 5 is 0.283662185463226

Example 2:




#!/usr/bin/perl
  
# Calling cos function
$var = cos(9);
  
# Printing value of cos(9)
print "cos value of 9 is $var";


Output:

cos value of 9 is -0.911130261884677

Similar Reads

Perl | Basic Syntax of a Perl Program
Perl is a general purpose, high level interpreted and dynamic programming language. Perl was originally developed for the text processing like extracting the required information from a specified text file and for converting the text file into a different form. Perl supports both the procedural and Object-Oriented programming. Perl is a lot similar
10 min read
Perl | chomp() Function
The chomp() function in Perl is used to remove the last trailing newline from the input string. Syntax: chomp(String) Parameters: String : Input String whose trailing newline is to be removed Returns: the total number of trailing newlines removed from all its arguments Example 1: C/C++ Code #!/usr/bin/perl # Initialising a string $string = &quo
2 min read
Perl | chop() Function
The chop() function in Perl is used to remove the last character from the input string. Syntax: chop(String) Parameters: String : It is the input string whose last characters are removed. Returns: the last removed character. Example 1: #!/usr/bin/perl # Initialising a string $string = "GfG is a computer science portal"; # Calling the chop
1 min read
Perl | rename() Function
rename() function in Perl renames the old name of a file to a new name as given by the user. Syntax: rename(old_file_path, new_file_path) Parameters: old_file_path: path of the old file along with its name new_file_path: path of the new file along with its name Returns 0 on failure and 1 on success Example: #!/usr/bin/perl -w # Calling the rename()
1 min read
Perl | sin() Function
This function is used to calculate sine of a VALUE or $_ if VALUE is omitted. This function always returns a floating point. Syntax: sin(VALUE) Parameters: VALUE in the form of float Returns: Function returns sine of VALUE. Example 1: #!/usr/bin/perl # Calling sin() function $var = sin(5); # Printing value for sin(5) print "sin value of 5 is $
1 min read
Perl | abs() function
This function returns the absolute value of its argument. If a pure integer value is passed then it will return it as it is, but if a string is passed then it will return zero. If VALUE is omitted then it uses $_ Syntax: abs(VALUE) Parameter: VALUE: It is a required number which can be either positive or negative or a string. Returns: Function retu
2 min read
Perl | atan2() Function
This function is used to calculate arctangent of Y/X in the range -PI to PI. Syntax: atan2(Y, X) Parameters: Y and X which are axis values Returns: Function returns arctangent of Y/X in the range -PI to PI. Example1: #!/usr/bin/perl # Assigning values to X and y $Y = 45; $X = 70; # Calling atan2() function $return_val = atan2($Y, $X); # printing th
1 min read
Perl | splice() - The Versatile Function
In Perl, the splice() function is used to remove and return a certain number of elements from an array. A list of elements can be inserted in place of the removed elements. Syntax: splice(@array, offset, length, replacement_list) Parameters: @array - The array in consideration. offset - Offset of removal of elements. length - Number of elements to
9 min read
Perl | delete() Function
Delete() in Perl is used to delete the specified keys and their associated values from a hash, or the specified elements in the case of an array. This operation works only on individual elements or slices. Syntax: delete(LIST) Parameters: LIST which is to be deleted Returns: undef if the key does not exist otherwise it returns the value associated
1 min read
Perl | defined() Function
Defined() in Perl returns true if the provided variable 'VAR' has a value other than the undef value, or it checks the value of $_ if VAR is not specified. This can be used with many functions to detect for the failure of operation since they return undef if there was a problem. If VAR is a function or reference of a function, then it returns true
2 min read