NumericalProperty broken with doubles?

27 views
Skip to first unread message

tmps...@gmail.com

unread,
Sep 6, 2017, 6:42:10 AM9/6/17
to Grph: High Performance Graph Library for Java
I might be doing something wrong, but seems to me that `NumericalProperty` is broken when retrieving numbers as double.

```
NumericalProperty p = new NumericalProperty("weight");
p.setValue(0, 10);

System.out.println(p.getValueAsDouble(0)); // 4.9E-323
System.out.println(p.getValueAsInt(0)); // 10
```

The side effect here is that I cannot use `Graph.getNeighborsAtMaxDistance` because it is using `getValueAsDouble` internally, so the comparison with `maxDistance` is always true.

I tested with `1.10.8` which is described on the website as the latest release. I also found a version `4.0.0` which uses `long` instead of `int`, but the bug is there too.

I reported this here too, but not sure if this repo is maintained: https://github.com/lhogie/grph/issues/2

Luc Hogie

unread,
Nov 6, 2017, 9:30:28 AM11/6/17
to Grph: High Performance Graph Library for Java
The key is: ints are not stored like doubles.

You set the value using a long value 10.
When you get it as int, no pb, ints and longs are stored in the same way.
This is another story with doubles.
If you plan to retrieve double values, you must use the setValue(int, double) setter via:

p.setValue(0, 10d);

instead of:

p.setValue(0, 10);

Luc Hogie

unread,
Nov 8, 2017, 4:59:49 AM11/8/17
to tmps...@gmail.com, Grph: High Performance Graph Library for Java
That's actually not a bug of Grph. This is the result of interpreting as double a set of bits initially representing a long value.


--
You received this message because you are subscribed to the Google Groups "Grph: High Performance Graph Library for Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grph-high-performance-graphs-for-java+unsubscribe@googlegroups.com.
To post to this group, send an email to grph-high-performance-graphs-for-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Luc Hogie 

Phone: 06 80 91 40 71

Skype: luchogie


"Je suis heureux parce que c'est bon pour la santé" Voltaire


Reply all
Reply to author
Forward
0 new messages