Forum > General
Random values of Extended type
jamie:
Looks like a nice home work project :o
1/Int64; :D
What ever.
TRon:
--- Quote from: jamie on April 07, 2024, 06:24:51 pm ---1/Int64; :D
--- End quote ---
If the precision does not matter than yes something to that extend ;D
--- Quote ---What ever.
--- End quote ---
Whenever :D
KodeZwerg:
I assume he wants to mirror his Int64 scaled on a -1.1 up to 0.1 extended float type.
Where -1.1 represents Low(Int64) and 0.1 represents High(Int64).
If it is like I say then the range troubles a lot, its really tight for such a big range of possibilities and second the negative/positive thingy...
In a simplified version that works with original values to compute the result, the result is sadly same if input-int64 has no significant changes.
Because of that I tried to upscale the Int64 into a QWord to do the same math, currently I do have a working version but still got bug inside.
In my case the bug is that the result is always negative, on the good side, no computed value appear twice.
I need to rethink my concept about how to scale it correctly but one question remains, what are you doing afterwards with that scaled value?
TRon:
--- Quote from: KodeZwerg on April 07, 2024, 09:10:56 pm ---I assume he wants to mirror his Int64 scaled on a -1.1 up to 0.1 extended float type.
--- End quote ---
In case it was not clear (yet), I interpreted it differently :-X
But it does not matter much whatever interpretation as there is simply not enough information to be able to provide the correct answer.
Does the prng create int64's in the full 64-bit range or only positive numbers, does TS require a particular scale to distribute positive and negative numbers evenly. And also the matter of precision.
Remapping is not really an issue though my quick approach gets into trouble after the 20th digit.
--- Quote ---I need to rethink my concept about how to scale it correctly but one question remains, what are you doing afterwards with that scaled value?
--- End quote ---
If answering that question provides more answer to the already unknown variables that TS left out then yes please answer :)
fiscraliger:
--- Quote from: TRon on April 07, 2024, 01:09:00 am ---
--- Quote from: fiscraliger on April 06, 2024, 11:54:05 pm ---In my case I have no such thing as "Random" to use. I have 64-bit signed integer from custom PRNG and I need to use it somehow to produce random Extended float in ranges -1,1 or 0,1.
--- End quote ---
Can't you simply divide your prng by 1 shl 63 (unsigned) to calculate a -1..1 range ?
--- End quote ---
I did this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---MaxInt64 := Power(2, 63); function Random_extended:extended;Var Numerator:Int64;BeginNumerator := MyPRNG_SignedRandom64;Result := Numerator / MaxInt64;End; function Random_extended_positive_only:extended;Var Numerator:Int64;BeginNumerator := MyPRNG_SignedRandom64;Result := Abs(Numerator / MaxInt64);End;
Previously I tried to fiddle with internal structure of Extended, first injecting random bits into it and then trying to "temper" mantissa and exponent separately, before passing the whole record as Extended, but I failed to correctly tune these elements, so there was plenty of errors.
Navigation
[0] Message Index
[#] Next page
[*] Previous page