Libraryless. Click here for Pure Java version (9154L/50K).
1 | static double ratioToProbability(double ratio) { |
2 | if (ratio < 0) fail("No negative values allowed"); |
3 | if (ratio > 1) ratio = 1/ratio; |
4 | ret ratio; |
5 | } |
6 | |
7 | static double ratioToProbability(double a, double b) { |
8 | if (a < 0 || b < 0) fail("No negative values allowed"); |
9 | ret b == 0 ? (a == 0 ? 1 : 0) : ratioToProbability(a/b); |
10 | } |
Began life as a copy of #1031994
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035513 |
Snippet name: | ratioToProbability - 1 is highest probability, any other ratio is lower |
Eternal ID of this version: | #1035513/1 |
Text MD5: | d376402528eeca62de55702d148ab417 |
Transpilation MD5: | ba02bd6d25aa43ca3e55c64680bc280d |
Author: | stefan |
Category: | javax / maths |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-06-01 17:55:06 |
Source code size: | 334 bytes / 10 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 117 / 156 |
Referenced in: | [show references] |