Computing.Net > Forums > Programming > How to solve 32-bits of precision problem?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to solve 32-bits of precision problem?

Reply to Message Icon

Name: fsloke
Date: July 4, 2009 at 23:14:10 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hi All,

I wrote a batch script as below:
I trying to add a number bigger than 2 million
ie 9011000513 to a increment number ie
1,2,3,4,5.

=================================
@echo off

setlocal ENABLEDELAYEDEXPANSION

set COUNT=9011000513

for %%v in (1 2 3 4) do (

SET /A COUNT=!COUNT!+%%v

echo !COUNT!

)

PAUSE

=================================

But It hits an error as below.
=================================
Invalid number. Numbers are limited to 32-bits
of precision.
9011000513
Invalid number. Numbers are limited to 32-bits
of precision.
9011000513
Invalid number. Numbers are limited to 32-bits
of precision.
9011000513
Invalid number. Numbers are limited to 32-bits
of precision.
9011000513
Press any key to continue . . .
=================================

How can I get the result of
9011000514
9011000515
9011000516
9011000517
9011000518?

Thanks

-fsloke



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: July 5, 2009 at 00:57:56 Pacific
Reply:

@echo off
setlocal enabledelayedexpansion
set COUNT=9011000513
for %%v in (1 2 3 4) do (
call :add COUNT %%v
echo !COUNT!
)
pause
goto :eof




:add
::call with two arguments, the variable name
::and the number to be added to the contents of the
::variable. the variable name will be set to the result

setlocal enabledelayedexpansion
set add1=!%1!
set add2=%2
set atotal=
set astore=
set acarry=
:aloop
if not defined add1 (
	if defined acarry (
		set add1=%acarry%
		set acarry=
	) else (
		set atotal=%add2%%atotal%
		goto aoutput
	)
)
if not defined add2 (
	if defined acarry (
		set add2=%acarry%
		set acarry=
	) else (
		set atotal=%add1%%atotal%
		goto aoutput
	)
)
if not defined acarry (
	set /a astore=%add1:~-1%+%add2:~-1%
) else (
	set /a astore=%add1:~-1%+%add2:~-1%+%acarry%
	set acarry=
)
if !astore! lss 10 (
	set atotal=%astore%%atotal%
) else (
	set atotal=%astore:~-1%%atotal%
	set acarry=%astore:~0,-1%
)
set astore=
set add1=%add1:~0,-1%
set add2=%add2:~0,-1%
goto aloop
:aoutput
endlocal&set %1=%atotal%
goto :eof


0
Reply to Message Icon

Related Posts

See More


Ideas for Software? Vb6.0 data reports



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: How to solve 32-bits of precision problem?

how to solve this error? www.computing.net/answers/programming/how-to-solve-this-error/4318.html

How to get 1st frame of AVI file/vi www.computing.net/answers/programming/how-to-get-1st-frame-of-avi-filevi/14952.html

how to solve this error??? www.computing.net/answers/programming/how-to-solve-this-error/4394.html