我能算到的阶乘有多大(三)

Author:水如烟 

大数的运算考虑只限于加、乘,暂不考虑减、除。
除比较麻烦。

上文方法中,将字串分解为字符来运算,耗内存,速度也慢。

现在考虑将字串分解为特定字串来运算。利用系统的加、乘运算。也就是确定运算单元。

利用.NET提供的数据类型,来确定特定字串的字符数。

Public   Class  Form1

    
Private   Sub  Button1_Click( ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  Button1.Click
        TestSystemType.Test()
    
End Sub


End Class

' 寻找最大的数值类型,其中某个数的平方其结果仍表示为整数
Public   Class  TestSystemType
    
Private   Sub   New ()
    
End Sub

    
Public   Shared   Sub  Test()
        
Dim  mTypeName  As   String
        
Dim  mType  As  Type
        
Dim  mFieldInfo  As  Reflection.FieldInfo
        
Dim  b  As   New  System.Text.StringBuilder

        
For   Each  c  As  TypeCode  In  [ Enum ].GetValues( GetType (TypeCode))

            mTypeName 
=  c.ToString
            mType 
=  Type.GetType( String .Format( " System.{0} " , mTypeName))

            mFieldInfo 
=  mType.GetField( " MaxValue " )
            
If  mFieldInfo  Is   Nothing   Then   Continue   For

            b.AppendLine()
            b.AppendLine(mTypeName)
            b.AppendLine(mFieldInfo.GetValue(
Nothing ).ToString)

        
Next

        Console.Write(b.ToString)
    
End Sub

End Class

测试结果:

Char
?

SByte
127

Byte
255

Int16
32767

UInt16
65535

Int32
2147483647

UInt32
4294967295

Int64
9223372036854775807

UInt64
18446744073709551615

Single
3.402823E+38

Double
1.79769313486232E+308

Decimal
79228162514264337593543950335

DateTime
9999-12-31 23:59:59

可以确定,利用的是Decimal数据类型。

Public   Class  Form1

    
Private   Sub  Button1_Click( ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  Button1.Click
        
Dim  x  As   Decimal   =   Decimal .MaxValue
        x 
=   CDec (Math.Sqrt(x))
        Console.WriteLine(x)
        
Dim  mDigits  As   Integer   =  x.ToString.Length
        Console.WriteLine(mDigits)
        mDigits 
-=   1
        Console.WriteLine(mDigits)
        
Dim  mMaxUnitString  As   String   =   New   String ( " 9 " c, mDigits)
        Console.WriteLine(mMaxUnitString)
        x 
=   Decimal .Parse(mMaxUnitString)
        x 
=  x  *  x
        Console.WriteLine(x)

    
End Sub


End Class

结果:

281474976710656
15
14
99999999999999
9999999999999800000000000001

现在确定,运算单元利用Decimal类型,定义字串为14位。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值