Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0007099 [Squeak] Kernel feature N/A 06-17-08 22:01 06-23-08 20:10
Reporter nicolas cellier View Status public  
Assigned To
Priority normal Resolution open  
Status new   Product Version 3.10
Summary 0007099: [FEATURE] Integer>>sqrtTruncated and sqrtRounded
Description It can be done in Integer arithmetic and implementation is fast.
And it won't suffer any potential inexact arithmetic problem raised by Float conversion...

That's why i prefer (x sqrtTruncated) to (x sqrt truncated)...

Additional Information TODO: implement for rationals...
Attached Files  Integer-sqrtTruncated-M7099.1.cs [^] (1,918 bytes) 06-17-08 23:13
 Integer-sqrtTruncated-Test-M7099.1.cs [^] (2,138 bytes) 06-17-08 23:14
 Integer-sqrtTruncated-Test-M7099.2.cs [^] (1,640 bytes) 06-17-08 23:17
 Fraction-sqrtTruncated-M7099.1.cs [^] (2,239 bytes) 06-18-08 00:44
 Fraction-sqrtTruncated-Test-M7099.1.cs [^] (1,258 bytes) 06-18-08 00:44

- Relationships

- Notes
(0012300 - 213 - 231 - 231 - 231 - 231 - 231)
nicolas cellier
06-17-08 23:18

Wrong changeset handling...
Integer-sqrtTruncated-Test-M7099.1.cs incorrectly includes/duplicates some methods from Integer-sqrtTruncated-M7099.1.cs

That's why there is a Integer-sqrtTruncated-Test-M7099.2.cs
 
(0012301 - 185 - 197 - 197 - 197 - 197 - 197)
nicolas cellier
06-17-08 23:24

When i think of it, raising a FloatingPointException in an integer arithmetic method is not the nicest thing to do!

This exception should better be renamed as an ArithmeticException.
 
(0012302 - 247 - 307 - 307 - 307 - 307 - 307)
nicolas cellier
06-18-08 00:24
edited on: 06-18-08 00:45

A good example of intermediate inexact arithmetic failure:

| x |
x := (1 bitShift: 53).
self assert: (x + (1/2)) squared sqrtRounded = (x+1)

fails if implemented asFloat sqrt rounded

I provide hereafter a first Fraction implementation

 
(0012307 - 490 - 682 - 1082 - 1082 - 1082 - 1082)
nicolas cellier
06-23-08 20:10

Andres Valloud who initiated my answer at http://groups.google.am/group/comp.lang.smalltalk/browse_thread/thread/179b982ac8562ccf [^] has posted on his blog a simular solution (See http://blogten.blogspot.com/2008/06/update-on-sqrtrounded.html) [^] :

sqrtRounded
    | x |
    x := (self * 4) sqrtTruncated.
    ^(x//2) + (x\\2)

which can also be written (may be more efficiently)

sqrtRounded
    | x |
    x := (self bitShift: 2) sqrtTruncated.
    ^(x bitShift: -1) + (x bitAnd: 1)
 

- Issue History
Date Modified Username Field Change
06-17-08 22:01 nicolas cellier New Issue
06-17-08 23:13 nicolas cellier File Added: Integer-sqrtTruncated-M7099.1.cs
06-17-08 23:14 nicolas cellier File Added: Integer-sqrtTruncated-Test-M7099.1.cs
06-17-08 23:17 nicolas cellier File Added: Integer-sqrtTruncated-Test-M7099.2.cs
06-17-08 23:18 nicolas cellier Note Added: 0012300
06-17-08 23:24 nicolas cellier Note Added: 0012301
06-18-08 00:24 nicolas cellier Note Added: 0012302
06-18-08 00:44 nicolas cellier File Added: Fraction-sqrtTruncated-M7099.1.cs
06-18-08 00:44 nicolas cellier File Added: Fraction-sqrtTruncated-Test-M7099.1.cs
06-18-08 00:45 nicolas cellier Note Edited: 0012302
06-23-08 20:10 nicolas cellier Note Added: 0012307


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
56 total queries executed.
32 unique queries executed.
Powered by Mantis Bugtracker