Abs() Double in Java

double java.lang.Math.abs(double a) 

abs(): This function returns the absolute value of a double value.If the argument is not negative, the argument is returned.If the argument is negative, the negation of theargument is returned.

Special cases: 

1.If the argument is positive zero or negative zero, the result is positive zero.

2.If the argument is infinite, the result is positive infinity.

3.If the argument is NaN, the result is NaN.

Parameters: One argument is required for this function.

arg: The argument whose absolute value is to be determined.

Returns: the absolute value of the argument.

Syntax:

Math.abs(arg)

For Example:

Math.abs(-12.45) = > It return 12.45

Approach

Java


public class AbsDouble {
    public static void main(String[] args) {

        double num = -12.45;
        System.out.println(Math.abs(num));

    }


Abs() float in Java

float java.lang.Math.abs(float a)

abs(): This function returns the absolute value of a float value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned. 

Special cases: 

1.If the argument is positive zero or negative zero, the result is positive zero. 

2.If the argument is infinite, the result is positive infinity.

3.If the argument is NaN, the result is NaN.

Parameters: One parameter is required for this function.

arg: The argument whose absolute value is to be determined.

Returns: the absolute value of the argument.

Syntax:

Math.abs(arg)

For Example:

Math.abs(-12.0) = > It returns 12

Approach

Java

public class AbsFloat {
    public static void main(String[] args) {

        float num = (float) -12.0;

        System.out.println(Math.abs(num));

    }
}


Abs() long in Java

long java.lang.Math.abs(long a)

abs(): This function returns the absolute value of a long value. If the argument is positive, the argument is returned. If the argument is negative, the negation of the argument is returned.

Note: If the argument is equal to the value of Long.MIN_VALUE, the most negative representable long value, the result is that same value, which is negative. In contrast, the Math.absExact(long) method throws an ArithmeticException for this value. 

Parameters: One parameter is required for this function.

arg: The argument whose absolute value is to be determined.

This function returns the absolute value of the argument.

Syntax:

Math.abs(arg)

For Example:

Math.abs(-1000000000) => It returns -1000000000.

Approach

Java

public class AbsLong {
    public static void main(String[] args) {

        long num = -1000000000;
        System.out.println(Math.abs(num));

    }
}


absExact() long in Java

absExact():This function returns the mathematical absolute value of an long value if it is exactly representable as an long, throwing ArithmeticException if the result overflows the positive long range. The mathematical absolute value of Long.MIN_VALUE overflows the positive long range, so an exception is thrown for that argument. 

Parameters: One parameter is required for this function.

arg: The argument whose absolute value is to be determined. 

It returns the absolute value of the argument, unless overflow occurs.

Throws: ArithmeticException - if the argument is Long.MIN_VALUE

Syntax:

Math.absExact(arg)

For Example:

Math.absExact(-199993393) = > It return 199993393.

Approach

Java

public class AbsExactLong {
    public static void main(String[] args) {

        long a = -199993393;
        System.out.println(Math.absExact(a));

    }
}


absExact() int in Java

int java.lang.Math.absExact(int a)

This function returns the mathematical absolute value of an int value if it is exactly representable as an int. This function throwing ArithmeticException if the result overflows the positive int range. The mathematical absolute value of Integer.MIN_VALUE overflows the positive int range, so an exception is thrown for that argument. 

Parameters: One parameter is required for this function.

arg: The argument whose absolute value is to be determined.

It returns the absolute value of the argument unless overflow occurs

Throws: ArithmeticException - if the argument is Integer.MIN_VALUE

Syntax:

absExact(arg)

For Example:

Math.absExact(-10) = > It return 10.

Approach

Java

public class AbsExactInt {
    public static void main(String[] args) {

        int a = -10;
        System.out.println(Math.absExact(a));

    }
}



Constant (PI) in Java

The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter (i.e 2*Ï€*r/2*r).

Value: 3.141592653589793

Syntax:

Math.PI = > It returns 3.141592653589793

Approach

Java

public class ValueofPI {
    public static void main(String[] args) {

        System.out.println(Math.PI);

    }
}


Constant (E) in Java

The double value that is closer than any other to e, the base of the natural logarithms.

Value:2.718281828459045

Syntax:

Math.E = > It return 2.718281828459045

Approach

Java


public class ValueofE {
    public static void main(String[] args) {

        System.out.println(Math.E);

    }
}


is_sorted_until() in C++

is_sorted_until(): This function is available in the file stl_algo.h. This function determines the end of a sorted sequence. This function returns an iterator pointing to the last iterator  i in [__first, __last) for which the range [__first, i) is sorted.

Parameters: Two parameters are required for this function.

__first – An iterator.

__last – Another iterator. 

Syntax:

vector<data_type>::iterator it = is_sorted_until(arr.begin(),arr.end())

For Example:

arr = {3,4,5,6,2,1}

is_sorted_until(arr.begin(),arr.end()) = > It return the iterator pointing to 2.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr = {345621};

    vector<int>::iterator it = is_sorted_until(arr.begin(), 
arr.end());

    cout << *it << "\n";

    return 0;
}


is_sorted() in C++

is_sorted(): This function is available in the file stl_algo.h. This function determines whether the elements of a sequence are sorted. This function returns true if the elements are sorted, false otherwise. 

Parameters: Two parameters are required for this function.

 __first – An iterator.

 __last – Another iterator.

Syntax:

is_sorted(__first, __last)

For Example:

arr = {1,4,6,8,10}

is_sorted(arr.begin(), arr.end()) = > It return true (1) because the given sequence is sorted.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr = {146810};

    cout << is_sorted(arr.begin(), arr.end()) << "\n";

    return 0;
}


is_permutation() in C++

is_permutation(): This function is available in the file stl_algo.h. This function checks whether any permutation of the second sequence is equal to the first sequence. This function returns true if there exists a permutation of the elements in the range [__first2, __first2 + (__last1 - __first1)), beginning with ForwardIterator2 begin, such that equal(__first1, __last1, begin) returns true; otherwise, returns false.

Parameters: Three parameters are required for this function. 

__first1 – Start of first range.

 __last1 – End of first range. 

__first2 – Start of the second range.

Syntax:

is_permutation(__first1, __last1, __first2)

For Example:

arr = {1,4,3}, vec = {4,3,1}

is_permutation(arr.begin(),arr.end(),vec.begin()) = > It return true (1).

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr = {143};

    vector<intvec = {431};

    cout << is_permutation(arr.begin(), arr.end(), 
vec.begin()) << "\n";

    return 0;
}



is_partitioned() in C++

is_partitioned(): This function is available in the file stl_algo.h. This function is used to checks whether the sequence is partitioned. 

Parameters: Three parameters are required for this function. 

__first – An input iterator.

 __last – An input iterator.

 __pred – A predicate.

This function returns true if the range [__first,__last) is partitioned by __pred, i.e. if all elements that satisfy __pred appear before those that do not.

Syntax:

is_partitioned(__first, __last, __pred)

For Example:

arr = {1,2,3,4}

is_partitioned(arr.begin(),arr.end(),[](int i){return i%2==0;}) = > It return false (0).

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr = {1234};

    cout << is_partitioned(arr.begin(), arr.end(), [](int i)
                           { return i % 2 == 0; })
         << "\n";
    

        return 0;
}


is_heap_until() in C++

is_heap_until(): This function is available in the file stl_heap.h. This function is used to searches the end of a heap. This function returns an iterator pointing to the first element, not in the heap.

Parameters: Two parameters are required for this function.

 __first – Start of range. 

__last – End of range. 

Syntax:

vector<data_type>::iterator it = is_heap_until(__first,__last)

For Example:

arr = { 7,3,4,1,2,10}

it = is_heap_until(arr.begin(),arr.end()) = > It returns the iterator pointing to 10 ( because 10 is the first element in the range not in the heap)

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr = {7341210};

    vector<int>::iterator it = is_heap_until(arr.begin(), 
arr.end());

    cout << *it << "\n";

    return 0;
}


is_heap() in C++

is_heap(): This function is available in the file stl_heap.h. This function checks the range of elements is in the heap or not. If the range is in the heap it will return true. Otherwise, it will return false.

Parameters: Two parameters are required for this function. 

__first – Start of range. 

__last – End of range.

Syntax:

is_heap(__first, __last)

For Example:

arr = {7,5,6,2,3,1,2}

is_heap(ar.begin(),arr.end()) = > It will return true (1)

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr = {7563412};

    cout << is_heap(arr.begin(), arr.end()) << "\n";

    return 0;
}



iota() in C++

iota(): This function is available in the file stl_numeric.h. This function creates a range of sequentially increasing values. For each element in the range [first, last) assigns value and increments value as if by ++value. 

Parameters: Three parameters are required for this function.

 __first – Start of range.

 __last – End of range.

 __value – Starting value. 

Returns: Nothing.

Syntax:

iota(__first , __last, __value)

For Example:

vector<int>arr (10)

iota(arr.begin(),arr.end(),10)  => It insert 10 elements in the array arr start from 10 to 19

arr ={10,11,12,13,14,15,16,17,18,19}

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr(10);
    iota(arr.begin(), arr.end(), 10);
    

    for (int i = 0i < arr.size(); i++)
        cout << arr[i] << " ";

    return 0;
}


internal in C++

internal: This is used to adjust the field by inserting characters at an internal position. This sets the adjusted field format flag for the str stream to internal.

Parameters: 

str: Stream object whose adjust field format flag is affected.

Syntax:

internal<<str

For Example:

str = "abcd"

width(10)<<internal<<str => It return     "abcd"

     abcd 

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    cout.width(10);
    cout << internal << "abcd\n";

    return 0;
}


inserter() in C++

inserter(): This function is available in the file stl_iterator.h.This function returns an instance of insert_iterator working on __x. This wrapper function helps in creating insert_iterator instances. Typing the name of the iterator requires knowing the precise full type of the container, which can be tedious and impedes generic programming. This function permits you to make the most of automatic template parameter deduction, making the compiler match the proper types for you.

Parameters: Two parameters are required for this function.

 __x – A container of arbitrary type.

 __i – An iterator into the container. 

Syntax:

inserter(__x, __i)

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intvec = {11030};
    vector<intarr = {4560};

    copy(arr.begin(), arr.end(), inserter(vecvec.begin()));

    for (int i = 0i < vec.size(); i++)
        cout << vec[i] << " ";

        return 0;
}


imaxabs() in C++

imaxabs(): This function is available in the file inttypes.h. This function computes the absolute value of the given number. It takes one argument in the type of intmax_t and returns the absolute value of it. It returns the value of type intmax_t.

Parameters: One parameter is required for this function.

j: The value whose absolute value is to be determined. The type of argument is intmax_t.

Syntax:

imaxabs(j)

For Example:

imaxabs(-10) = > It returns 10.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    intmax_t j = -10;
    cout << imaxabs(j<< "\n";

    return 0;
}


imag() in C++

imag(): This function is available in the file complex. This function returns the imaginary part of the complex number. It takes one argument as a complex number.

Parameters: One parameter is required for this function.

__X: The complex number whose imaginary part is to be determined.

Syntax:

imag(__X)

For Example:

complexNum (12,10)

imag(complexNum) = > It returns 10.

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    complex<doublecomplexNum(1210);

    cout << imag(complexNum<< "\n";

    return 0;
}

ilogbl() in C++

ilogbl(): This function is available in the file math.h. This function extracts the value of the unbiased exponent from the floating-point argument arg, and returns it as a signed integer value.

Parameters: One parameter is required for this function.

arg: The floating-point value.

Syntax:

ilogbl(arg)

For Example:

ilogbl(1000.25) = > It returns 9.

i

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    long double x = 1000.25;

    cout << ilogbl(x<< "\n";

    return 0;
}


imaxdiv() in C++

imaxdiv(): This function is available in the file inttypes.h. This function computes the quotient and the remainder of two integer values of any size as a single operation. This function return Value imaxdiv called with arguments of type intmax_t returns a structure of type imaxdiv_t that comprises the quotient and the remainder.

Parameters: Two parameters are required for this function.

numer- The numerator. 

denom -The denominator.

Syntax:

imaxdiv(numer, denom)

For Example:

imaxdiv(10,3) = > The values returned as quot = 3 rem = 1

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    intmax_t numer = 10denom = 3;

    imaxdiv_t res = imaxdiv(numerdenom);

    cout << "quot = " << res.quot << " rem = " 
<< res.rem << "\n";

    return 0;
}


inner_product() in C++

inner_product(): This function is available in the file stl_numeric.h. This function computes the inner product of two ranges. Starting with an initial value of __init. 

Multiplies successive elements from the two ranges and adds each product into the accumulated value using operator+(). The values in the ranges are processed in the order. It returns the final inner product.

Parameters:

 __first1 – Start of range 1. 

__last1 – End of range 1. 

__first2 – Start of range 2.

 __init – Starting value to add other values to it.

Syntax:

inner_product(__first1, __last1, __first2, __init)

For Example:

arr = {1, 2, 3, 10}, vec = {4, 5, 6, 45, 10}

inner_product(arr.begin(), arr.end(), vec.begin(),0) => It return the value 482.

1*4 + 2*5 + 3*6 + 10*45 =  482

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intarr = {12310};
    vector<intvec = {4564510};

    cout << inner_product(arr.begin(), arr.end(), 
vec.begin(), 0<< "\n";

    return 0;
}