Getting the result unrounded Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Getting the result unrounded

26 Oct 2021, 15:44

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.
Last edited by BoBo on 26 Oct 2021, 15:57, edited 1 time in total.
Reason: Changed subject line from unspecific "A Question" to "Getting the result unrounded"
teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: A Question  Topic is solved

26 Oct 2021, 15:53

Code: Select all

Msgbox % Format("{:.10f}", 1/2**10)
garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: Getting the result unrounded

27 Oct 2021, 11:04

@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
teadrinker
Posts: 4325
Joined: 29 Mar 2015, 09:41
Contact:

Re: Getting the result unrounded

27 Oct 2021, 11:46

I don't know, perhaps there are some libraries for this.
sofista
Posts: 650
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Getting the result unrounded

27 Oct 2021, 12:22

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
garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: Getting the result unrounded

27 Oct 2021, 13:48

@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
*/
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Getting the result unrounded

29 Oct 2021, 14:57

@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 512 times
Code:

Code: Select all

Msgbox % Format("{:.100f}", 0.1024 * 16)
RussF
Posts: 1260
Joined: 05 Aug 2021, 06:36

Re: Getting the result unrounded

29 Oct 2021, 16:28

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
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Getting the result unrounded

29 Oct 2021, 17:18

Thank you @RussF for the explanation.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Giresharu, inseption86, jomaweb, KruschenZ, mikeyww, Rohwedder and 277 guests