Math.floor method

Класс Java Math

Класс Java Math предоставляет более сложные математические вычисления, чем те, которые предоставляют базовые математические операторы Java. Класс Math содержит методы для:

  • нахождения максимального или минимального значений;
  • значений округления;
  • логарифмических функций;
  • квадратного корня;
  • тригонометрических функций (sin, cos, tan и т. д.).

Math находится в пакете java.lang, а не в пакете java.math. Таким образом, полное имя класса Math – это java.lang.Math.

Поскольку многие его функции независимы друг от друга, каждый метод будет объяснен в своем собственном разделе ниже.

Python NumPy

NumPy IntroNumPy Getting StartedNumPy Creating ArraysNumPy Array IndexingNumPy Array SlicingNumPy Data TypesNumPy Copy vs ViewNumPy Array ShapeNumPy Array ReshapeNumPy Array IteratingNumPy Array JoinNumPy Array SplitNumPy Array SearchNumPy Array SortNumPy Array FilterNumPy Random
Random Intro
Data Distribution
Random Permutation
Seaborn Module
Normal Distribution
Binomial Distribution
Poisson Distribution
Uniform Distribution
Logistic Distribution
Multinomial Distribution
Exponential Distribution
Chi Square Distribution
Rayleigh Distribution
Pareto Distribution
Zipf Distribution

NumPy ufunc
ufunc Intro
ufunc Create Function
ufunc Simple Arithmetic
ufunc Rounding Decimals
ufunc Logs
ufunc Summations
ufunc Products
ufunc Differences
ufunc Finding LCM
ufunc Finding GCD
ufunc Trigonometric
ufunc Hyperbolic
ufunc Set Operations

9.2.1. Number-theoretic and representation functions¶

(x)

Return the ceiling of x as a float, the smallest integer value greater than or
equal to x.

(x, y)

Return x with the sign of y. On a platform that supports
signed zeros, returns -1.0.

New in version 2.6.

(x)

Return the absolute value of x.

(x)

Return x factorial. Raises if x is not integral or
is negative.

New in version 2.6.

(x)

Return the floor of x as a float, the largest integer value less than or equal
to x.

(x, y)

Return , as defined by the platform C library. Note that the
Python expression may not return the same result. The intent of the C
standard is that be exactly (mathematically; to infinite
precision) equal to for some integer n such that the result has
the same sign as x and magnitude less than . Python’s
returns a result with the sign of y instead, and may not be exactly computable
for float arguments. For example, is , but
the result of Python’s is , which cannot be
represented exactly as a float, and rounds to the surprising . For
this reason, function is generally preferred when working with
floats, while Python’s is preferred when working with integers.

(x)

Return the mantissa and exponent of x as the pair . m is a float
and e is an integer such that exactly. If x is zero,
returns , otherwise . This is used to “pick
apart” the internal representation of a float in a portable way.

(iterable)

Return an accurate floating point sum of values in the iterable. Avoids
loss of precision by tracking multiple intermediate partial sums:

>>> sum()
0.9999999999999999
>>> fsum()
1.0

The algorithm’s accuracy depends on IEEE-754 arithmetic guarantees and the
typical case where the rounding mode is half-even. On some non-Windows
builds, the underlying C library uses extended precision addition and may
occasionally double-round an intermediate sum causing it to be off in its
least significant bit.

For further discussion and two alternative approaches, see the ASPN cookbook
recipes for accurate floating point summation.

New in version 2.6.

(x)

Check if the float x is positive or negative infinity.

New in version 2.6.

(x)

Check if the float x is a NaN (not a number). For more information
on NaNs, see the IEEE 754 standards.

New in version 2.6.

(x, i)

Return . This is essentially the inverse of function
.

(x)

Return the fractional and integer parts of x. Both results carry the sign
of x and are floats.

(x)

Return the value x truncated to an
(usually a long integer). Uses the
method.

New in version 2.6.

Note that and have a different call/return pattern
than their C equivalents: they take a single argument and return a pair of
values, rather than returning their second return value through an ‘output
parameter’ (there is no such thing in Python).

9.2.2. Power and logarithmic functions¶

(x)

Return .

(x)

Return . For small floats x, the subtraction in
can result in a significant loss of precision; the
function provides a way to compute this quantity to
full precision:

>>> from math import exp, expm1
>>> exp(1e-5) - 1  # gives result accurate to 11 places
1.0000050000069649e-05
>>> expm1(1e-5)    # result accurate to full precision
1.0000050000166668e-05

New in version 2.7.

(x, base)

With one argument, return the natural logarithm of x (to base e).

With two arguments, return the logarithm of x to the given base,
calculated as .

Changed in version 2.3: base argument added.

(x)

Return the natural logarithm of 1+x (base e). The
result is calculated in a way which is accurate for x near zero.

New in version 2.6.

(x)

Return the base-10 logarithm of x. This is usually more accurate
than .

(x, y)

Return raised to the power . Exceptional cases follow
Annex ‘F’ of the C99 standard as far as possible. In particular,
and always return , even
when is a zero or a NaN. If both and are finite,
is negative, and is not an integer then
is undefined, and raises .

Unlike the built-in operator, converts both
its arguments to type . Use or the built-in
function for computing exact integer powers.

Changed in version 2.6: The outcome of and was undefined.

Python NumPy

NumPy IntroNumPy Getting StartedNumPy Creating ArraysNumPy Array IndexingNumPy Array SlicingNumPy Data TypesNumPy Copy vs ViewNumPy Array ShapeNumPy Array ReshapeNumPy Array IteratingNumPy Array JoinNumPy Array SplitNumPy Array SearchNumPy Array SortNumPy Array FilterNumPy Random
Random Intro
Data Distribution
Random Permutation
Seaborn Module
Normal Distribution
Binomial Distribution
Poisson Distribution
Uniform Distribution
Logistic Distribution
Multinomial Distribution
Exponential Distribution
Chi Square Distribution
Rayleigh Distribution
Pareto Distribution
Zipf Distribution

NumPy ufunc
ufunc Intro
ufunc Create Function
ufunc Simple Arithmetic
ufunc Rounding Decimals
ufunc Logs
ufunc Summations
ufunc Products
ufunc Differences
ufunc Finding LCM
ufunc Finding GCD
ufunc Trigonometric
ufunc Hyperbolic
ufunc Set Operations

Example

The following example shows the usage of lang.Math.pow() method.

package com.tutorialspoint;

import java.lang.*;

public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers
      double x = 2.0;
      double y = 5.4;
   
      // print x raised by y and then y raised by x
      System.out.println("Math.pow(" + x + "," + y + ")=" + Math.pow(x, y));
      System.out.println("Math.pow(" + y + "," + x + ")=" + Math.pow(y, x));
   }
}

Let us compile and run the above program, this will produce the following result −

Math.pow(2.0, 5.4)=42.22425314473263
Math.pow(5.4, 2.0)=29.160000000000004

java_lang_math.htm

Previous Page
Print Page

Next Page  

Trigonometric functions¶

(x)

Return the arc cosine of x, in radians.

(x)

Return the arc sine of x, in radians.

(x)

Return the arc tangent of x, in radians.

(y, x)

Return , in radians. The result is between and .
The vector in the plane from the origin to point makes this angle
with the positive X axis. The point of is that the signs of both
inputs are known to it, so it can compute the correct quadrant for the angle.
For example, and are both , but is .

(x)

Return the cosine of x radians.

(p, q)

Return the Euclidean distance between two points p and q, each
given as a sequence (or iterable) of coordinates. The two points
must have the same dimension.

Roughly equivalent to:

sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))

New in version 3.8.

(*coordinates)

Return the Euclidean norm, .
This is the length of the vector from the origin to the point
given by the coordinates.

For a two dimensional point , this is equivalent to computing
the hypotenuse of a right triangle using the Pythagorean theorem,
.

Changed in version 3.8: Added support for n-dimensional points. Formerly, only the two
dimensional case was supported.

(x)

Return the sine of x radians.

Загрузка изображения из URL в Pillow

В следующем примере показано, как получить изображение, указав его URL адрес.

Python

from PIL import Image
import requests
import sys

url = ‘https://i.ytimg.com/vi/vEYsdh6uiS4/maxresdefault.jpg’

try:
resp = requests.get(url, stream=True).raw
except requests.exceptions.RequestException as e:
sys.exit(1)

try:
img = Image.open(resp)
except IOError:
print(«Unable to open image»)
sys.exit(1)

img.save(‘sid.jpg’, ‘jpeg’)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

fromPIL importImage

importrequests

importsys

url=’https://i.ytimg.com/vi/vEYsdh6uiS4/maxresdefault.jpg’

try

resp=requests.get(url,stream=True).raw

exceptrequests.exceptions.RequestException ase

sys.exit(1)

try

img=Image.open(resp)

exceptIOError

print(«Unable to open image»)

sys.exit(1)

img.save(‘sid.jpg’,’jpeg’)

Код читает изображение через его URL и сохраняет его на диск.

Python

import requests

1 importrequests

Мы используем библиотеку requests для загрузки изображения.

Python

resp = requests.get(url, stream=True).raw

1 resp=requests.get(url,stream=True).raw

Изображение читается как данные .

Python

img = Image.open(resp)

1 img=Image.open(resp)

Картинка создается из ответного объекта .

Python

img.save(‘sid.jpg’, ‘jpeg’)

1 img.save(‘sid.jpg’,’jpeg’)

И в конечном итоге изображение сохраняется.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Adblock
detector