Hello everyone,
@Demivec : Thanks for your input, I will revise those macros later.
I have a partial solution for Squaring values unfortunately it work fine up to 3037000499. For any value bigger than that I don't have the solution yet and I have seen values bigger than that.
This is the not optimized code for the moment.
Code:
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Simulation of Squaring Unsigned long
; File Name : Simulation of Squaring Unsigned long.pb
; File version: 0.0.0
; Programming : Under development
; Programmed by : StarBootics
; Date : November 5th,2020
; Last Update : November 5th,2020
; PureBasic code : V5.73 beta 2
; Platform : Windows, Linux, MacOS X
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Procedure.q Addition(VarA.q, VarB.q)
Result.q = VarA + VarB
If Result > 4294967295
Result = Result - 4294967296
EndIf
If Result < 0
Result = 4294967296 + Result
EndIf
ProcedureReturn Result
EndProcedure
Procedure.q Squaring(Value.q)
Square.q = Value * Value
Output.q = 0
If Square < 0
; This portion of the code just don't work at all
Debug "Square Négatif (" + Str(Value) + ")"
Output = Addition(Output, 2147483647)
Output = Addition(Output, -1533320537)
Amount2.q = Square * -1
Debug Amount2
HowManyLoopOfWaste = Amount2 / 4294967295
Debug -HowManyLoopOfWaste
Amount2 = Amount2 - HowManyLoopOfWaste * 4294967295
Debug Amount2
Output = Addition(Output, Amount2)
Output = Addition(Output, -HowManyLoopOfWaste)
;
ElseIf Square > 0
; This portion of the code work just fine
Debug "Square Positif (" + Str(Value) + ")"
HowManyLoopOfWaste = Square / 4294967295
Amount.q = Square - HowManyLoopOfWaste * 4294967295
Output = Addition(Output, Amount)
Output = Addition(Output, -HowManyLoopOfWaste)
EndIf
ProcedureReturn Output
EndProcedure
Debug Squaring(3037000499) ; Squaring this value still fit inside of the
; positive portion of a Quad. The simulated
; unsigned value is Correct
Debug Squaring(3037000500) ; Squaring this value don't fit inside the
; positive portion of a Quad. The simulated
; unsigned value is not Correct
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
@Fred : if you ever read this topic please consider adding unsigned long variables back into PureBasic. Even if certain operations like comparing signed and unsigned values are not possible I can live with that. I know I'm pushing the PureBasic envelope by doing this just to see if it's possible but with unsigned long this project will be completed already.
Best regards
StarBootics