Changeset 385 for trunk/Include/basic/function.sbp
- Timestamp:
- Nov 20, 2007, 12:04:07 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/basic/function.sbp
r383 r385 427 427 End Function 428 428 429 Dim _System_ecvt_buffer[16] As StrChar 430 Sub _ecvt_support(count As Long) 429 Sub _ecvt_support(buf As *StrChar, count As Long, size As Long) 431 430 Dim i As Long 432 If _System_ecvt_buffer[count]=9 Then433 _System_ecvt_buffer[count]=0434 If count =0 Then435 For i =16To 1 Step -1436 _System_ecvt_buffer[i]=_System_ecvt_buffer[i-1]431 If buf[count] = 9 Then 432 buf[count] = 0 433 If count = 0 Then 434 For i = size To 1 Step -1 435 buf[i] = buf[i-1] 437 436 Next 438 _System_ecvt_buffer[0]=1437 buf[0] = 1 439 438 Else 440 _ecvt_support( count-1)441 End If 442 Else 443 _System_ecvt_buffer[count]++439 _ecvt_support(buf, count-1, size) 440 End If 441 Else 442 buf[count]++ 444 443 End If 445 444 End Sub 446 Function _ecvt(value As Double, count As Long, ByRef dec As Long, ByRef sign As Long) As *StrChar 445 446 Sub _ecvt(buffer As *StrChar, value As Double, count As Long, ByRef dec As Long, ByRef sign As Boolean) 447 447 Dim i As Long, i2 As Long 448 449 _ecvt=_System_ecvt_buffer450 448 451 449 '値が0の場合 452 450 If value = 0 Then 453 ActiveBasic.Strings.ChrFill( _System_ecvt_buffer, count As SIZE_T, &H30 As StrChar)454 _System_ecvt_buffer[count] = 0451 ActiveBasic.Strings.ChrFill(buffer, count As SIZE_T, &h30 As StrChar) 452 buffer[count] = 0 455 453 dec = 0 456 454 sign = 0 … … 460 458 '符号の判断(同時に符号を取り除く) 461 459 If value < 0 Then 462 sign = 1460 sign = True 463 461 value = -value 464 462 Else 465 sign = 0463 sign = False 466 464 End If 467 465 … … 477 475 Wend 478 476 479 For i=0 To count-1 480 _System_ecvt_buffer[i] = Int(value) As StrChar 481 477 For i = 0 To count - 1 478 buffer[i] = Int(value) As StrChar 482 479 value = (value-CDbl(Int(value))) * 10 483 480 Next 484 _System_ecvt_buffer[i] = 0485 481 486 482 i-- 487 483 If value >= 5 Then 488 484 '切り上げ処理 489 _ecvt_support( i)490 End If 491 492 For i =0 To ELM(count)493 _System_ecvt_buffer[i] += &H30485 _ecvt_support(buffer, i, count) 486 End If 487 488 For i = 0 To count - 1 489 buffer[i] += &H30 494 490 Next 495 _System_ecvt_buffer[i] = 0496 End Function491 buffer[i] = 0 492 End Sub 497 493 498 494 Function Str$(dbl As Double) As String … … 506 502 End If 507 503 End If 508 Dim dec As Long, sign As Long509 Dim buffer[32] As StrChar, temp As *StrChar510 Dim i As Long, i2 As Long, i3As Long504 Dim dec As Long, sign As Boolean 505 Dim buffer[32] As StrChar, temp[15] As StrChar 506 Dim i = 0 As Long 511 507 512 508 '浮動小数点を文字列に変換 513 temp = _ecvt(dbl, 15, dec, sign) 514 515 i=0 509 _ecvt(temp, dbl, 15, dec, sign) 516 510 517 511 '符号の取り付け … … 521 515 End If 522 516 523 If dec >15Then524 '指数表示 (桁が大きい場合)517 If dec > 15 Or dec < -3 Then 518 '指数表示 525 519 buffer[i] = temp[0] 526 520 i++ … … 529 523 ActiveBasic.Strings.ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T) 530 524 i += 14 531 buffer[i] = Asc("e") 532 i++ 533 _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1) 'ToDo: __STRING_UNICODE_WINDOWS_ANSI状態への対応 534 535 Return MakeStr(buffer) 536 End If 537 538 If dec < -3 Then 539 '指数表示(桁が小さい場合) 540 buffer[i] = temp[0] 541 i++ 542 buffer[i] = Asc(".") 543 i++ 544 ActiveBasic.Strings.ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T) 545 i+=14 546 buffer[i] = Asc("e") 547 i++ 548 _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1) 'ToDo: __STRING_UNICODE_WINDOWS_ANSI状態への対応 549 550 Return MakeStr(buffer) 525 buffer[i] = 0 526 Return MakeStr(buffer) + ActiveBasic.Strings.SPrintf("e%+03d", New System.Int32(dec - 1)) 551 527 End If 552 528 553 529 '整数部 554 i2=dec555 i3=0530 Dim i2 = dec 531 Dim i3 = 0 556 532 If i2>0 Then 557 533 While i2>0 … … 593 569 End Function 594 570 595 Function Str$(i As Int64) As String 596 If i < 0 Then 597 Return "-" & Str$(-i As QWord) 598 Else 599 Return Str$(i As QWord) 600 End If 571 Function Str$(x As Int64) As String 572 Imports ActiveBasic.Strings.Detail 573 Return FormatIntegerEx(TraitsIntegerD[1], x As QWord, 1, 0, None) 601 574 End Function 602 575 603 576 Function Str$(x As QWord) As String 604 If x = 0 Then 605 Return "0" 606 End If 607 608 Dim buf[20] As StrChar 609 'buf[20] = 0 610 Dim i = 19 As Long 611 Do 612 buf[i] = (x Mod 10 + &h30) As StrChar 613 x \= 10 614 If x = 0 Then 615 Exit Do 616 End If 617 i-- 618 Loop 619 Return New String(VarPtr(buf[i]), 20 - i) 577 Imports ActiveBasic.Strings.Detail 578 Return FormatIntegerEx(TraitsIntegerU[1], x, 1, 0, None) 620 579 End Function 621 580 622 581 Function Str$(x As Long) As String 623 #ifdef _WIN64 624 Return Str$(x As Int64) 625 #else 626 If x < 0 Then 627 Return "-" & Str$(-x As DWord) 628 Else 629 Return Str$(x As DWord) 630 End If 631 #endif 582 Imports ActiveBasic.Strings.Detail 583 Return FormatIntegerEx(TraitsIntegerD[0], x, 1, 0, None) 632 584 End Function 633 585 634 586 Function Str$(x As DWord) As String 635 #ifdef _WIN64 636 Return Str$(x As QWord) 637 #else 638 If x = 0 Then 639 Return "0" 640 End If 641 642 Dim buf[10] As StrChar 643 buf[10] = 0 644 Dim i = 9 As Long 645 Do 646 buf[i] = (x As Int64 Mod 10 + &h30) As StrChar 'Int64への型変換は#117対策 647 x \= 10 648 If x = 0 Then 649 Return New String(VarPtr(buf[i]), 10 - i) 650 End If 651 i-- 652 Loop 653 #endif 587 Imports ActiveBasic.Strings.Detail 588 Return FormatIntegerEx(TraitsIntegerU[0], x, 1, 0, None) 654 589 End Function 655 590 656 591 Function Str$(x As Word) As String 657 Return Str$(x As ULONG_PTR)592 Return Str$(x As DWord) 658 593 End Function 659 594 660 595 Function Str$(x As Integer) As String 661 Return Str$(x As L ONG_PTR)596 Return Str$(x As Long) 662 597 End Function 663 598 664 599 Function Str$(x As Byte) As String 665 Return Str$(x As ULONG_PTR)600 Return Str$(x As DWord) 666 601 End Function 667 602 668 603 Function Str$(x As SByte) As String 669 Return Str$(x As L ONG_PTR)604 Return Str$(x As Long) 670 605 End Function 671 606
Note:
See TracChangeset
for help on using the changeset viewer.