dnazirzhanov05's blog

By dnazirzhanov05, history, 4 years ago, In Russian

#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!

  • Vote: I like it
  • -10
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 2   Vote: I like it +13 Vote: I do not like it

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.