3

I am currently trying to debug an uninitialized memory error. I have now come across the numerical literal 0.e0f in the OpenBlas source code (which is what the debugger is currently at) what does that mean?

The context is this:

if ((alpha_r == 0.e0f) && (alpha_i == 0.e0f)) return;

The 0.e0f evaluates to 0 apparently.

Blackclaws
  • 436
  • 5
  • 20
  • If I'm not wrong, 0.e0f is a zero (or something very close to zero) in a floating point number representation. This will be just a guess... Do you have a -lm option on in your compilation command? – Marek Jul 16 '14 at 10:04

4 Answers4

5

A floating-point literals have two syntaxes. The first one consists of the following parts:

  • nonempty sequence of decimal digits containing a decimal point character (defines significand)
  • (optional) e or E followed with optional minus or plus sign and nonempty sequence of decimal digits (defines exponent)
  • (optional) a suffix type specifier as a l, f, L or F

The second one consists of the following parts:

  • nonempty sequence of decimal digits (defines significant)
  • e or E followed with optional minus or plus sign and nonempty sequence of decimal digits (defines exponent)
  • (optional) a suffix type specifier as a l, f, L or F

The suffix type specifier defines the actual type of the floating-point literal:

  • (no suffix) defines double
  • f F defines float
  • l L defines long double
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
3

f floating point indicator

eX is exponent value for 10 to the power of X. for example e5 means 10 to the 5 which is 100000. or e-3 means 0.001.

Combining the two

1.23e-3f --> 1.23 x 10 ^ -3 = 0.00123

By expanding your example it is

0.e0f --> 0.0 x 10 ^ 0 = 0.0 (in floating point format)

PS: A useful programming practice. Never ever (see PS2) compare two floating point numbers for equality.

There are some values cannot be represented exactly by floating points just approximations. Like this example

0.3 + 0.6 = 0.89999999999999991 != 0.9

Instead use:

float a;
float b;

....

if( abs(a-b) < FLT_EPSILON )

FLT_EPLISON is a very small floating point value where 1.0 + FLT_EPSILON != 1.0. (example 0.1e-10) (Quoted from @AlterMann)

abs is short for absolute function for floating points; which in std is fabs. Can be found in other libraries with different names too.

PS 2: OK... Never ever had been a little strong. I didn't mean that this piece of code is wrong neither as algorithm nor syntax. Question itself is a bit simple though this warning may help the new programmers end up here.

As in comments stated this code example is appropriate for checking. 0 check is a valid operation, because current standards for floating point representation guarantee that 0 can be expressed.

ifyalciner
  • 1,190
  • 1
  • 10
  • 22
  • +1, good point, good to say that `FLT_EPSILON` is the minimum positive number such that 1.0 + FLT_EPSILON != 1.0. `if( abs(a-b) < FLT_EPSILON )` seems a better option – David Ranieri Jul 16 '14 at 10:30
  • Saying "never" is going too far IMO. It can be valid to compare a float with 0, for example in a loop where you are decreasing the float by a constant factor, so that it will get to 0. Moreover your preferred solution is sometimes the same as comparing for equality (eg when both numbers are bigger than 4) and sometimes unlikely to be useful (eg when both numbers are themselves smaller than FLT_EPSILON). Finally, a typo, I think; it should be fabsf, not abs. – dmuir Jul 16 '14 at 10:47
  • Actually in your example is where you should omit the floating pointer comparison. Integration operations will more likely to cause numeric differences. Some of the intermediate values of counter may not be able to represent in floating point. Comparing with 0 can be acceptable but still I think this is a better practice. The desired action is that `if` to behave as equality. And the FLT_EPSILON depends your architecture and application. That's why Floating points are dangerous for checking equality. `abs` is to shorten `absolute` not indicating a library function but is better to state too. – ifyalciner Jul 16 '14 at 10:55
  • This is a situation in which comparing for equality is absolutely correct. The code in question is testing if a complex number `alpha` is zero (meaning really zero, not “sorta zero” or “kinda small”). Using any approximate comparison involving tolerances would be a bug. – Stephen Canon Jul 16 '14 at 11:06
  • Correct the code is from OpenBlas so anything that is not truly zero would result in some computation being done which is the desired result as far as I can tell. – Blackclaws Jul 16 '14 at 11:30
  • Yes thats rigth but my warning doesn't state for example in question. It is obviously stated that OP didn't write the given code. That is why also my explanation is in PS instead of answer itself. Thought new programmers would benefit from it though stated question itself is bit simple. – ifyalciner Jul 16 '14 at 12:05
  • In C, correct to use `fabs(a-b)` or `fabsf(a-b)` than `abs(a-b)`. "abs is short for absolute function for floating points" confuses. `abs()` is a function for `int`. – chux - Reinstate Monica Jul 11 '16 at 17:41
0

It's zero in scientific notation, as single-precision floating point, with a redundant decimal mark. It's the same thing as 0e0.

Cilph
  • 115
  • 2
  • 8
0

That's a 0 of type float.

See 6.4.4.2 in the C99 Standard ( http://port70.net/~nsz/c/c99/n1256.html#6.4.4.2 )

In my opinion a plain 0 would be better irrespective of the type of alpha_r and alpha_i

if ((alpha_r == 0) && (alpha_i == 0)) return;
pmg
  • 106,608
  • 13
  • 126
  • 198