Commit Graph
18 Commits
Author SHA1 Message Date
Todor Balabanov 763149e2f4 Double values comparison changed to compare method.
Using the Double.compare() method is often preferred over the == comparison
operator for comparing double values due to several reasons:

Handling NaN (Not-a-Number) values: The Double.compare() method correctly
handles NaN values, while the == operator does not. If either of the operands
is NaN, the == operator will always return false, regardless of the other
operand. In contrast, Double.compare() will correctly evaluate NaN values
according to the IEEE 754 floating-point standard.

Handling positive and negative zero: The == operator treats positive zero and
negative zero as equal, whereas they are distinct values in IEEE 754
floating-point representation. Double.compare() correctly distinguishes
between positive and negative zero.

Robustness against rounding errors: Floating-point arithmetic can introduce
rounding errors, causing two double values that should be equal to differ
slightly. Directly comparing them with the == operator might yield unexpected
results due to these small differences. Double.compare() allows you to define
a tolerance level if necessary, providing more control over how equality is
determined.

Consistent behavior: The behavior of Double.compare() is consistent and
predictable across different platforms and JVM implementations, as it follows
the IEEE 754 standard. On the other hand, the behavior of the == operator
might vary depending on the platform and compiler optimizations.

Suitability for sorting: Double.compare() returns an integer value that can
be directly used for sorting double values in ascending or descending order.
This makes it convenient for sorting arrays or collections of double values.

Overall, while the == operator might work in some cases, using
Double.compare() provides more robust and predictable behavior, especially
when dealing with floating-point numbers in Java.

Change-Id: I5756936a0d2b4fe11b9113ddd33b6ae691f5103f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166796
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2024-04-29 15:40:27 +02:00
Todor Balabanov 559b342a62 The null pointer bug should be fixed now.
Change-Id: I8278bfed8170907a958396839d0997fc127f4b2e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119744
Tested-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-08-02 08:41:14 +02:00
Todor Balabanov 7b93bae224 Some lower objects coupling.
Change-Id: I0a7c658d830f82d627d20b9ed7000f3c5b8f1f89
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119105
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-07-17 22:22:17 +02:00
Todor Balabanov a71caa79c8 Object initialization is done via a constructor with parameters.
Change-Id: I66e87f7c898efb1f2c6b1d31fbd5654244e3ea82
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118785
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-07-13 09:57:41 +02:00
Todor Balabanov 822f128e73 Polymorphism is a better approach when there are chains of inheritance.
Change-Id: I2580dafcf8792bf4b11db78988db8c2976e4545c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118569
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
2021-07-08 03:49:56 +02:00
Todor Balabanov 89459662bf Global optimization metaheuristics sometimes are sensitive to the quality of the random numbers.
Change-Id: Ibc1e95736c5f9355e67f2129a7804064e329da89
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117510
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-06-21 08:48:50 +02:00
Todor Balabanov ffef53274b It is a good practice single source of random numbers to be used.
Change-Id: If76e247461288a9ed938b4f6cb592c814b8bbe2b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117406
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
2021-06-20 03:59:07 +02:00
Todor Balabanov 72cd9250a8 A separate function for getting a random search point is a little bit clearer.
Change-Id: I2d7471440cdee096b09ce704cbea3d5311f984c8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117289
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-06-17 20:41:37 +02:00
Todor Balabanov b3bf90ec5f Fewer array reference calls make the code more readable and more efficient.
Change-Id: I7416633a735078a4e0e857f050ea7bfaadba310c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117158
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Jenkins
2021-06-15 06:03:52 +02:00
Todor Balabanov a2720a2432 Checking of min and max factor value was added.
It is possible user to swap these two values.

Change-Id: Ib375d705e42f7257aa9b16d72ab834020e401cde
Reviewed-on: https://gerrit.libreoffice.org/72483
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
2019-06-03 16:12:17 +02:00
Todor Balabanov 90ace7be71 Range for DE scaling factor was implemented.
Change-Id: I5b8d3cd69a6138d7eebf37c299626019b32d639a
Reviewed-on: https://gerrit.libreoffice.org/72373
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
2019-06-03 15:53:30 +02:00
Todor Balabanov 5ee453818c Some additional manual formatting.
Change-Id: Ie5590535d013aa2f747dd034fa2fcd2ae5c3956b
Reviewed-on: https://gerrit.libreoffice.org/72226
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
2019-05-17 08:45:46 +02:00
Todor Balabanov 51387dc280 Formatting - Eclipse IDE Java Conventions with spaces for indentation.
Change-Id: I0c3e50ef25bda0bc4ae59665a07848fe75507121
Reviewed-on: https://gerrit.libreoffice.org/72185
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Tested-by: Jenkins
2019-05-12 22:50:34 +02:00
Todor Balabanov c728bb5420 Generate behavior code simplification and very small speed-up.
Change-Id: Ib13080e4c21738affa129d12a07f5380f665e7a4
Reviewed-on: https://gerrit.libreoffice.org/71673
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
2019-05-12 04:04:54 +02:00
Todor Balabanov 7aeef2e88b Import of each class is better practice than import of entire library.
Change-Id: I13c4916b951d36ea5e83e52c9c6e36df552bdfeb
Reviewed-on: https://gerrit.libreoffice.org/71961
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2019-05-10 08:49:42 +02:00
Todor Balabanov b596210c09 Fisher-Yates shuffling algorithm achieves much better randomization.
Change-Id: I6d204a7ba0fa19f4c318d1c70f5a0344e0640d6d
Reviewed-on: https://gerrit.libreoffice.org/71620
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-05-01 16:15:24 +02:00
Todor Balabanov 209e40de80 Random class is better than Math random function.
Change-Id: Ia35e3bb3b4f0323c7fbfc54ae5064afdf2c3f381
Reviewed-on: https://gerrit.libreoffice.org/71539
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-05-01 16:11:30 +02:00
Todor Balabanov df512e7475 Math pow is too slow in this case.
Change-Id: I16149cabf75ec928d96975e4b98622df6951cefc
Reviewed-on: https://gerrit.libreoffice.org/71519
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2019-05-01 16:10:45 +02:00