Skip to content

`addWordC` for other word sizes.

Summary

Let's add addWord64C#.

I'm trying to use addWordC# for Word64 calculations.

Because this does not exist I couldn't find it, I've had to use word64ToWord# and wordToWord64#.

Current sub-optimal solution:

addChecked (W64# a1) (W64# a2) =                  
  -- Note: We have to use conversions from W64# <-> W# because
  -- there is no addWord64C# in GHC.Exts (yet?)
  case addWordC# (word64ToWord# a1) (word64ToWord# a2) of
    (# resultW#, overflowInt# #) ->
      if isTrue# overflowInt#
        then Nothing
        else Just (W64# (wordToWord64# resultW#))  

Note that this is silently wrong on 32-bit architectures, which is why I'm opening this issue.

Expected behavior

Proposed solution:

addChecked (W64# a1) (W64# a2) =                  
  case addWord64C# a1 a2 of                              
    (# resultW#, overflowInt# #) ->
      if isTrue# overflowInt#
        then Nothing     
        else Just (W64# resultW#) 
Edited by syd@cs-syd.eu
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information