Skip to content

Commit 47c7d6e

Browse files
committed
Fixed digit_count
For digit_count in stdlib_bitsets_large.fypp replaced the select case construct with a do loop and a divide by ten. [ticket: X]
1 parent ecd6c82 commit 47c7d6e

File tree

1 file changed

+11
-74
lines changed

1 file changed

+11
-74
lines changed

src/stdlib_bitsets_large.fypp

Lines changed: 11 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,83 +1254,20 @@ contains
12541254
integer(bits_kind), intent(in) :: bits
12551255
integer(bits_kind), intent(out) :: digits
12561256

1257-
if ( bits_kind == int32 ) then
1258-
select case ( bits )
1259-
case ( 0_int32:9_int32 )
1260-
digits = 1
1261-
case ( 10_int32:99_int32 )
1262-
digits = 2
1263-
case ( 100_int32:999_int32 )
1264-
digits = 3
1265-
case ( 1000_int32:9999_int32 )
1266-
digits = 4
1267-
case ( 10000_int32:99999_int32 )
1268-
digits = 5
1269-
case ( 100000_int32:999999_int32 )
1270-
digits = 6
1271-
case ( 1000000_int32:9999999_int32 )
1272-
digits = 7
1273-
case ( 10000000_int32:99999999_int32 )
1274-
digits = 8
1275-
case ( 100000000_int32:999999999_int32 )
1276-
digits = 9
1277-
case ( 1000000000_int32:huge(0_int32) )
1278-
digits = 10
1279-
case default
1280-
error stop module_name // ' % ' // procedure // &
1281-
' internal consistency fault was found.'
1282-
end select
1283-
1284-
else if ( bits_kind == int64 ) then
1285-
select case ( bits )
1286-
case ( 0_int64:9_int64 )
1287-
digits = 1
1288-
case ( 10_int64:99_int64 )
1289-
digits = 2
1290-
case ( 100_int64:999_int64 )
1291-
digits = 3
1292-
case ( 1000_int64:9999_int64 )
1293-
digits = 4
1294-
case ( 10000_int64:99999_int64 )
1295-
digits = 5
1296-
case ( 100000_int64:999999_int64 )
1297-
digits = 6
1298-
case ( 1000000_int64:9999999_int64 )
1299-
digits = 7
1300-
case ( 10000000_int64:99999999_int64 )
1301-
digits = 8
1302-
case ( 100000000_int64:999999999_int64 )
1303-
digits = 9
1304-
case ( 1000000000_int64:9999999999_int64 )
1305-
digits = 10
1306-
case ( 10000000000_int64:99999999999_int64 )
1307-
digits = 11
1308-
case ( 100000000000_int64:999999999999_int64 )
1309-
digits = 12
1310-
case ( 1000000000000_int64:9999999999999_int64 )
1311-
digits = 13
1312-
case ( 10000000000000_int64:99999999999999_int64 )
1313-
digits = 14
1314-
case ( 100000000000000_int64:999999999999999_int64 )
1315-
digits = 15
1316-
case ( 1000000000000000_int64:9999999999999999_int64 )
1317-
digits = 16
1318-
case ( 10000000000000000_int64:99999999999999999_int64 )
1319-
digits = 17
1320-
case ( 100000000000000000_int64:999999999999999999_int64 )
1321-
digits = 18
1322-
case ( 1000000000000000000_int64:huge(0_int64) )
1323-
digits = 19
1324-
case default
1325-
error stop module_name // ' % ' // procedure // &
1326-
' internal consistency fault was found.'
1327-
end select
1257+
integer(bits_kind) :: factor
13281258

1329-
else
1330-
error stop module_name // ' % ' // procedure // &
1331-
' internal consistency fault was found.'
1259+
factor = bits
1260+
1261+
if ( factor <= 0 ) then
1262+
digits = 1
1263+
return
13321264
end if
13331265

1266+
do digits = 1, 127
1267+
factor = factor / 10
1268+
if ( factor == 0 ) return
1269+
end do
1270+
13341271
end subroutine digit_count
13351272

13361273
end subroutine write_bitset_string_large

0 commit comments

Comments
 (0)