<commit_before>{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-|
    Module      :  Numeric.AERN.RealArithmetic.Basis.Double.Mutable
    Description :  mutable version of Double
    Copyright   :  (c) <NAME>
    License     :  BSD3

    Maintainer  :  <EMAIL>
    Stability   :  experimental
    Portability :  portable
    
    One, zero, negation etc for Double numbers.

    This is a private module reexported publicly via its parent.
-}

module Numeric.AERN.RealArithmetic.Basis.Double.Mutable where

import Numeric.AERN.Basics.Mutable
import Numeric.AERN.Basics.NumericOrder

import Numeric.AERN.RealArithmetic.ExactOps
import Numeric.AERN.RealArithmetic.NumericOrderRounding 

import Numeric.AERN.RealArithmetic.Basis.Double.FieldOps
import Numeric.AERN.RealArithmetic.Basis.Double.MixedFieldOps

import Data.STRef
import Data.Ratio


instance CanBeMutable Double where
    data Mutable Double s = 
        MDouble { unMDouble :: STRef s Double }
    makeMutable a = 
        do
        v <- newSTRef a
        return $ MDouble v  
    unsafeMakeMutable = makeMutable
    writeMutable (MDouble v) a = writeSTRef v a  
    unsafeWriteMutable = writeMutable
    readMutable (MDouble v) = readSTRef v  
    unsafeReadMutable = readMutable 
    sameVariable (MDouble v1) (MDouble v2) = v1 == v2

instance RoundedLatticeInPlace Double
    where
    maxUpInPlaceEff = maxUpInPlaceEffFromPure
    maxDnInPlaceEff = maxDnInPlaceEffFromPure
    minUpInPlaceEff = minUpInPlaceEffFromPure
    minDnInPlaceEff = minDnInPlaceEffFromPure

instance NegInPlace Double
    where
    negInPlace = pureToMutable1 neg
     
instance RoundedAddInPlace Double
    where
    addUpInPlaceEff = addUpInPlaceEffFromPure
    addDnInPlaceEff = addDnInPlaceEffFromPure
    <commit_msg>added debugging code in Double in-place negation instances<commit_after>{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-|
    Module      :  Numeric.AERN.RealArithmetic.Basis.Double.Mutable
    Description :  mutable version of Double
    Copyright   :  (c) <NAME>
    License     :  BSD3

    Maintainer  :  <EMAIL>
    Stability   :  experimental
    Portability :  portable
    
    One, zero, negation etc for Double numbers.

    This is a private module reexported publicly via its parent.
-}

module Numeric.AERN.RealArithmetic.Basis.Double.Mutable where

import Numeric.AERN.Basics.Mutable
import Numeric.AERN.Basics.NumericOrder

import Numeric.AERN.RealArithmetic.ExactOps
import Numeric.AERN.RealArithmetic.NumericOrderRounding 

import Numeric.AERN.RealArithmetic.Basis.Double.FieldOps
import Numeric.AERN.RealArithmetic.Basis.Double.MixedFieldOps

import Data.STRef
import Data.Ratio

import Control.Monad.ST (unsafeIOToST)


instance CanBeMutable Double where
    data Mutable Double s = 
        MDouble { unMDouble :: STRef s Double }
    makeMutable a = 
        do
        v <- newSTRef a
        return $ MDouble v  
    unsafeMakeMutable = makeMutable
    writeMutable (MDouble v) a = writeSTRef v a  
    unsafeWriteMutable = writeMutable
    readMutable (MDouble v) = readSTRef v  
    unsafeReadMutable = readMutable 
    sameVariable (MDouble v1) (MDouble v2) = v1 == v2

instance RoundedLatticeInPlace Double
    where
    maxUpInPlaceEff = maxUpInPlaceEffFromPure
    maxDnInPlaceEff = maxDnInPlaceEffFromPure
    minUpInPlaceEff = minUpInPlaceEffFromPure
    minDnInPlaceEff = minDnInPlaceEffFromPure

instance NegInPlace Double
    where
    negInPlace = pureToMutable1 neg
--    negInPlace resM pM =
--        do
--        res <- readMutable resM
--        p <- readMutable pM
--        unsafeIOToST $ putStrLn $ "Double negInPlace starting: (resM = " ++ show res ++ ", pM = " ++ show p ++ ")"
--        pureToMutable1 neg resM pM
--        res <- readMutable resM
--        p <- readMutable pM
--        unsafeIOToST $ putStrLn $ "Double negInPlace finishing: (resM = " ++ show res ++ ", pM = " ++ show p ++ ")"
     
instance RoundedAddInPlace Double
    where
    addUpInPlaceEff = addUpInPlaceEffFromPure
    addDnInPlaceEff = addDnInPlaceEffFromPure
    
{'fraction_non_alphanumeric': 0.0704529115744069, 'fraction_numerical': 0.003115264797507788, 'mean_word_length': 3.174, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1090385', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1356, 'n_words': 322}