From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA13069; Tue, 27 Mar 2001 19:49:51 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA13065 for ; Tue, 27 Mar 2001 19:49:50 +0200 (MET DST) Received: from c012.sfo.cp.net (c012-h022.c012.sfo.cp.net [209.228.12.170]) by nez-perce.inria.fr (8.11.1/8.10.0) with SMTP id f2RHnnT07061 for ; Tue, 27 Mar 2001 19:49:49 +0200 (MET DST) Received: (cpmta 4200 invoked from network); 27 Mar 2001 09:49:47 -0800 Date: 27 Mar 2001 09:49:47 -0800 Message-ID: <20010327174947.4199.cpmta@c012.sfo.cp.net> X-Sent: 27 Mar 2001 17:49:47 GMT Received: from [206.49.216.243] by mail.altavista.com with HTTP; 27 Mar 2001 09:49:47 PST Content-Type: text/plain Content-Disposition: inline Mime-Version: 1.0 To: wester@ilt.fhg.de From: Arturo Borquez Cc: caml-list@inria.fr X-Mailer: Web Mail 3.9.0.19 Subject: Re: [Caml-list] Complex numbers in OCaml Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, 27 March 2001, wester@ilt.fhg.de wrote: > > Hi, > > I need complex numbers. I tried it this way: > > type number = Real of float | Complex of (float*float);; > > let add_num a b = > match (a,b) with > (Real a, Real b) -> Real (a +. b) > | (Real a, Complex (bx,by)) -> Complex (a +. bx, by) ................. Hi: Rolf: Here is a little example of an alternative to operate with complex numbers. The key is to define a complex a a duple and define new opertators to do computations, ie +! for addition -! for substraction *! /!... let (+!) (xr, xi) (yr, yi) = (xr +. yr), (xi +. yi);; let a = (1.0, 2.0);; let b = (0.0, -4.75);; let z = a +! b;; z;; val z : float * float = 1, -2.75 The same applies for sub, mpy and div ops. hope this helps. Best regards. Arturo Borquez Find the best deals on the web at AltaVista Shopping! http://www.shopping.altavista.com ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr