Ignore:
Timestamp:
Nov 25, 2007, 4:31:35 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

Stringなどで例外を投げるようにした。
#147の解決。
CType ASCII文字判定関数群の追加。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/basic/function.sbp

    r385 r388  
    7878
    7979Function pow(x As Double, y As Double) As Double
    80     If -LONG_MAX<=y and y<=LONG_MAX and y=CDbl(Int(y)) Then
    81         pow=ipow(x,y As Long)
     80'   If -LONG_MAX<=y and y<=LONG_MAX and y=CDbl(Int(y)) Then
     81    If y = (y As Long) Then
     82        pow = ipow(x, y As Long)
     83    ElseIf x>0 Then
     84        pow = Exp(y * Log(x))
    8285        Exit Function
    83     End If
    84 
    85     If x>0 Then
    86         pow=Exp(y*Log(x))
    87         Exit Function
    88     End If
    89 
    90     If x<>0 or y<=0 Then
    91         'error
    92     End If
    93 
    94     pow=0
     86    ElseIf x<>0 or y<=0 Then
     87        pow = ActiveBasic.Math.Detail.GetNaN()
     88    Else
     89        pow = 0
     90    End If
    9591End Function
    9692
     
    272268        Return New String(c As StrChar, 1)
    273269    ElseIf c < &h10FFFF Then
    274         Dim t[1] = [&hD800 Or (c >> 10), &hDC00 Or (c And &h3FF)] As StrChar
     270        Dim t[1] = [&hD800 Or (c >> 10), &hDC00 Or (c And &h3FF)] As WCHAR
    275271        Return New String(t, 2)
    276272    Else
     
    306302End Function
    307303
    308 Dim _System_HexadecimalTable[&h10] = [&h30, &h31, &h32, &h33, &h34, &h35, &h36, &h37, &h38, &h39, &h41, &h42, &h43, &h44, &h45, &h46] As Byte
    309 
    310 Function _System_Hex(x As DWord, zeroSuppress As Boolean) As String
    311     Dim s[7] As StrChar
    312     Dim i As Long
    313     For i = 0 To ELM(Len (s) \ SizeOf (StrChar))
    314         s[i] = _System_HexadecimalTable[x >> 28] As StrChar
    315         x <<= 4
    316     Next
    317     If zeroSuppress Then
    318         Dim i As Long
    319         For i = 0 To 6
    320             If s[i] <> &h30 Then 'Asc("0")
    321                 Exit For
    322             End If
    323         Next
    324         Return New String(VarPtr(s[i]) As *StrChar, Len (s) \ SizeOf (StrChar) - i)
    325     Else
    326         Return New String(s As *StrChar, Len (s) \ SizeOf (StrChar))
    327     End If
    328 End Function
    329 
    330304Function Hex$(x As DWord) As String
    331     Hex$ = _System_Hex(x, True)
     305    Imports ActiveBasic.Strings.Detail
     306    Hex$ = FormatIntegerX(x, 1, 0, None)
    332307End Function
    333308
    334309Function Hex$(x As QWord) As String
    335     If HIDWORD(x) = 0 Then
    336         Hex$ = _System_Hex(LODWORD(x), True)
    337     Else
    338         Hex$ = _System_Hex(HIDWORD(x), True) + _System_Hex(LODWORD(x), False)
    339     End If
     310    Imports ActiveBasic.Strings.Detail
     311    Hex$ = FormatIntegerLX(x, 1, 0, None)
    340312End Function
    341313
     
    391363End Function
    392364
    393 Const _System_MaxFigure_Oct_QW = 22 As DWord 'QWORD_MAX = &o1,777,777,777,777,777,777,777
    394365Function Oct$(n As QWord) As String
    395     Dim s[ELM(_System_MaxFigure_Oct_QW)] As StrChar
    396     Dim i = ELM(_System_MaxFigure_Oct_QW) As Long
    397     Do
    398         s[i] = ((n And &o7) + &h30) As StrChar '&h30 = Asc("0")
    399         n >>= 3
    400         If n = 0 Then
    401             Return New String(s + i, _System_MaxFigure_Oct_QW - i)
    402         End If
    403         i--
    404     Loop
    405 End Function
    406 
    407 Const _System_MaxFigure_Oct_DW = 11 As DWord 'DWORD_MAX = &o37,777,777,777
     366    Imports ActiveBasic.Strings.Detail
     367    Oct$ = FormatIntegerLO(n, 1, 0, None)
     368End Function
     369
    408370Function Oct$(n As DWord) As String
    409     Dim s[ELM(_System_MaxFigure_Oct_DW)] As StrChar
    410     Dim i = ELM(_System_MaxFigure_Oct_DW) As Long
    411     Do
    412         s[i] = ((n And &o7) + &h30) As StrChar '&h30 = Asc("0")
    413         n >>= 3
    414         If n = 0 Then
    415             Return New String(s + i, _System_MaxFigure_Oct_DW - i)
    416         End If
    417         i--
    418     Loop
     371    Imports ActiveBasic.Strings.Detail
     372    Oct$ = FormatIntegerO(n, 1, 0, None)
    419373End Function
    420374
     
    493447
    494448Function Str$(dbl As Double) As String
    495     If ActiveBasic.Math.IsNaN(dbl) Then
     449    Imports ActiveBasic.Math
     450    Imports ActiveBasic.Strings
     451    If IsNaN(dbl) Then
    496452        Return "NaN"
    497     ElseIf ActiveBasic.Math.IsInf(dbl) Then
     453    ElseIf IsInf(dbl) Then
    498454        If dbl > 0 Then
    499455            Return "Infinity"
     
    521477        buffer[i] = Asc(".")
    522478        i++
    523         ActiveBasic.Strings.ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T)
     479        ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T)
    524480        i += 14
    525481        buffer[i] = 0
    526         Return MakeStr(buffer) + ActiveBasic.Strings.SPrintf("e%+03d", New System.Int32(dec - 1))
     482        Return MakeStr(buffer) + SPrintf("e%+03d", New System.Int32(dec - 1))
    527483    End If
    528484
     
    637593    If String.IsNullOrEmpty(s) Then
    638594        Return New String(0 As StrChar, n)
    639             Else
     595    Else
    640596        Return New String(s[0], n)
    641597    End If
     
    971927
    972928/*!
    973 @brief  ABオブジェクトを指すポインタをObject型へ変換。
     929@brief  ObjPtrの逆。ABオブジェクトを指すポインタをObject型へ変換。
    974930@author Egtra
    975931@date   2007/08/24
     
    1012968End Function
    1013969
    1014 Function _System_ASCII_IsUpper(c As WCHAR) As Boolean
    1015     Return c As DWord - &h41 < 26 ' &h41 = Asc("A")
    1016 End Function
    1017 
    1018 Function _System_ASCII_IsUpper(c As SByte) As Boolean
    1019     Return _System_ASCII_IsUpper(c As Byte As WCHAR)
    1020 End Function
    1021 
    1022 Function _System_ASCII_IsLower(c As WCHAR) As Boolean
    1023     Return c As DWord - &h61 < 26 ' &h61 = Asc("a")
    1024 End Function
    1025 
    1026 Function _System_ASCII_IsLower(c As SByte) As Boolean
    1027     Return _System_ASCII_IsLower(c As Byte As WCHAR)
    1028 End Function
    1029 
    1030 Function _System_ASCII_ToLower(c As WCHAR) As WCHAR
    1031     If _System_ASCII_IsUpper(c) Then
    1032         Return c Or &h20
    1033     Else
    1034         Return c
    1035     End If
    1036 End Function
    1037 
    1038 Function _System_ASCII_ToLower(c As SByte) As SByte
    1039     Return _System_ASCII_ToLower(c As Byte As WCHAR) As Byte As SByte
    1040 End Function
    1041 
    1042 Function _System_ASCII_ToUpper(c As WCHAR) As WCHAR
    1043     If _System_ASCII_IsLower(c) Then
    1044         Return c And (Not &h20)
    1045     Else
    1046         Return c
    1047     End If
    1048 End Function
    1049 
    1050 Function _System_ASCII_ToUpper(c As SByte) As SByte
    1051     Return _System_ASCII_ToUpper(c As Byte As WCHAR) As Byte As SByte
    1052 End Function
    1053 
    1054970Function _System_GetHashFromWordArray(p As *Word, n As SIZE_T) As Long
    1055971    Dim hash = 0 As DWord
Note: See TracChangeset for help on using the changeset viewer.