zweidenker / Units

A simple package for units
MIT License
16 stars 9 forks source link

How to add unit with no linear conversion? #25

Open labordep opened 3 weeks ago

labordep commented 3 weeks ago

Hi @MarcusDenker! I'm trying to implement the decibel unit. This is based on the watt but without a "linear" conversion. The conversion from db to w is

10 raisedTo: (db-30 / 10)

I'm adding a new unit with this value in watt:

self
        abbreviation: 'dB'
        name: 'decibel'
        pluralName: 'decibels'
        value: ((10 raisedTo: ((1 - 30) / 10)) units: Unit watt). 

but when I'm trying to convert 30dB in Watt this is 0.3w and not 1 (because 30dB=1W):

30 decibel convertTo: #watt =>0.037767762353824993 watts

I suppose this is normal and I don't know how to write the conversion formula (and also the reverse too).

How I can implement that?

Thanks.

MarcusDenker commented 6 days ago

Sorry for the late answer. I have sadly no idea myself, I will have a look as soon as I find time

labordep commented 5 days ago

Thanks @MarcusDenker, interessed to take a look!