Page 1 of 1

Getting the result unrounded

Posted: 26 Oct 2021, 15:44
by Smile_
Is it possible to get the result unrounded? or at least control it in case the decimal part is endless.

Code: Select all

Msgbox % 1 / (2 ** 10) ; gives 0.000977
I want it as 1 / (2¹⁰) = 0,0009765625.

Re: A Question  Topic is solved

Posted: 26 Oct 2021, 15:53
by teadrinker

Code: Select all

Msgbox % Format("{:.10f}", 1/2**10)

Re: Getting the result unrounded

Posted: 27 Oct 2021, 11:04
by garry
@teadrinker , is it possible to calculate with big numbers ?

Code: Select all

a1:=111111111*111111111      ;- 12345678987654321
a2:=1/2**10                  ;- .000977
r2:=Format("{:.10f}",A2)     ;- .0009765625
a3:=a1+r2                    ;- 12345678987654320.000000  > should be 12345678987654321.0009765625
ep:=12345678987654321.0009765625  ;- expected
msgbox,A1=%a1%`nA2=%a2%`nR2=%r2%`nA3=%a3%`nEP=%ep%
return

Re: Getting the result unrounded

Posted: 27 Oct 2021, 11:46
by teadrinker
I don't know, perhaps there are some libraries for this.

Re: Getting the result unrounded

Posted: 27 Oct 2021, 12:21
by malcev

Re: Getting the result unrounded

Posted: 27 Oct 2021, 12:22
by sofista
garry wrote:
27 Oct 2021, 11:04
is it possible to calculate with big numbers ?
I think so. I have used it very occasionally, but try with Maths.ahk:
https://raw.githubusercontent.com/aviaryan/autohotkey-scripts/master/Functions/Maths.ahk

Code: Select all

#Include D:\Aplications\Maths.ahk ; Replace with your copy of Maths.ahk

a1:=111111111*111111111      ;- 12345678987654321
a2:=1/2**10                  ;- .000977
MsgBox, % SM_Add(a1, a2)     ; 12345678987654321.000977
return

Re: Getting the result unrounded

Posted: 27 Oct 2021, 13:48
by garry
@sofista thank you , it works ( script maths.ahk from Avi Aryan )

Code: Select all

#Include <maths>
;-"C:\Program Files\AutoHotkey\LIB"   > here is Maths.ahk
;-
a1:=111111111*111111111      ;- 12345678987654321
a2:=1/2**10                  ;- .000977
MsgBox, % SM_Add(a1, a2)     ;- 12345678987654321.000977
return

/*
- https://raw.githubusercontent.com/aviaryan/autohotkey-scripts/master/Functions/Maths.ahk
Scientific MATHS LIBRARY ( Filename = Maths.ahk ) by Avi Aryan v3.43
------------------------------------------------------------------------------
Thanks to hd0202, smorgasbord, Uberi and sinkfaze
Special thanks to smorgasbord for the factorial function
------------------------------------------------------------------------------
DOCUMENTATION - http://avi-aryan.github.io/ahk/functions/smaths.html
Math-Functions.ahk - https://github.com/avi-aryan/Avis-Autohotkey-Repo/blob/master/Functions/Math-Functions.ahk
*/

Re: Getting the result unrounded

Posted: 29 Oct 2021, 14:57
by Smile_
@teadrinker, @garry, @malcev, @sofista, do you have any idea why this one is presenting here? it is supposed to be equal to 1.6384
2021-10-29_205229.png
2021-10-29_205229.png (13.18 KiB) Viewed 526 times
Code:

Code: Select all

Msgbox % Format("{:.100f}", 0.1024 * 16)

Re: Getting the result unrounded

Posted: 29 Oct 2021, 16:28
by RussF
That's just because of the difficulty that computers have in representing some floating point numbers.

Watch https://www.youtube.com/watch?v=PZRI1IfStY0 for a good explanation of why.

Russ

Re: Getting the result unrounded

Posted: 29 Oct 2021, 17:18
by Smile_
Thank you @RussF for the explanation.