Блог пользователя dnazirzhanov05

Автор dnazirzhanov05, история, 4 года назад, По-русски

#include <bits/stdc++.h>

using namespace std;

double area(int x1, int y1, int x2, int y2, int x3, int y3) {

return fabs(1.*(x2 — x1)*(y3 — y1)-(1.*(x3 — x1)*(y2 — y1)))/2.;

}

main() {

int x1, y1, x2, y2, x3, y3, a, b, c;

cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

cout << fixed << area(x1, y1, x2, y2, x3, y3);

}

In this code I don't understand what does 1. mean.

Thank you for your advice!

  • Проголосовать: нравится
  • -10
  • Проголосовать: не нравится

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

1. is essentially the same as 1.0 but $$$1$$$ character shorter. This . shows compiler that you want to have floating point contant value here and you can omit leading zeroes before . and trailing zeroes after .. For example you can also use .5 as 0.5 and .25 as 0.25.

In this case especially multiplying by floating point $$$1$$$ does not change the value of expression but forces compiler to use floating point calculations for whole expression. We can also achieve this by type casting like (double)x but 1.*x is shorter.